From 6c37ddb1fda4463862b43b0e7d990bd433543896 Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 14 Aug 2022 10:19:02 +0200 Subject: [PATCH] show folder icons next to folders --- go-sh-manymanuals.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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)