diff --git a/go-sh-manymanuals.go b/go-sh-manymanuals.go index 6161c99..5c97768 100644 --- a/go-sh-manymanuals.go +++ b/go-sh-manymanuals.go @@ -36,10 +36,9 @@ type model struct { } func initialModel() model { - viper.SetConfigFile("config.json") - viper.ReadInConfig() folder := viper.Get("ManualDir").(string) manuals, err := gatherManuals(folder) + if err != nil { log.Fatalf("unable to read manuals: %s", err) os.Exit(1) @@ -50,15 +49,19 @@ func initialModel() model { } } -func gatherManuals(folder string) ([]string, error) { - fileInfos, err := ioutil.ReadDir(fmt.Sprintf("./%s", folder)) +func gatherManuals(directory string) ([]string, error) { + fileInfos, err := ioutil.ReadDir(fmt.Sprintf("./%s", directory)) if err != nil { return nil, err } var filenames []string for _, fileInfo := range fileInfos { - filenames = append(filenames, fileInfo.Name()) + filename := fileInfo.Name() + if fileInfo.IsDir() { + filename = fmt.Sprintf("📁 %s", fileInfo.Name()) + } + filenames = append(filenames, filename) } return filenames, nil @@ -113,6 +116,9 @@ func main() { os.Exit(0) } + viper.SetConfigFile("config.json") + viper.ReadInConfig() + p := tea.NewProgram(initialModel(), tea.WithAltScreen()) if err := p.Start(); err != nil { fmt.Printf("Alas, there's been an error: %v", err)