diff options
author | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-15 00:08:39 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-15 00:08:39 +0530 |
commit | 028632de277704fe4576e732d4997daa70f25f60 (patch) | |
tree | 343137fc2b19cb7c9568324a9529218ca6065e49 /ui/search.go | |
parent | 5ac21806f34a7c88d2685420d53cbd585f4b4f3d (diff) |
added color coding and error handling + other visual appeal
Diffstat (limited to 'ui/search.go')
-rw-r--r-- | ui/search.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ui/search.go b/ui/search.go index ee25604..c02ae22 100644 --- a/ui/search.go +++ b/ui/search.go @@ -20,23 +20,26 @@ package ui import ( "strings" - "log" + "fmt" + "os" p "github.com/manifoldco/promptui" mal "github.com/MikunoNaka/macli/mal" + a "github.com/MikunoNaka/MAL2Go/anime" ) // only search animes probably only now -func SearchAndGetID(label, searchString string) int { +func AnimeSearch(label, searchString string) a.Anime { // TODO: load promptLength from config promptLength := 5 - animes := mal.SearchAnime(searchString) + extraFields := []string{"my_list_status"} + animes := mal.SearchAnime(searchString, extraFields) template := &p.SelectTemplates { Label: "{{ . }}", Active: "{{ .Title | magenta }}", Inactive: "{{ .Title }}", - Selected: "{{ .Title }}", + Selected: "{{ .Title | blue }}", Details: ` --------- {{ .Title }} ---------- More Details To Be Added Later @@ -58,11 +61,13 @@ More Details To Be Added Later Size: promptLength, } + var anime a.Anime animeIndex, _, err := prompt.Run() if err != nil { - log.Println(err) - return 0 + fmt.Println("Error running search menu.", err.Error()) + os.Exit(1) } - return animes[animeIndex].Id + anime = animes[animeIndex] + return anime } |