From 028632de277704fe4576e732d4997daa70f25f60 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 15 Jun 2022 00:08:39 +0530 Subject: added color coding and error handling + other visual appeal --- ui/search.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'ui/search.go') 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 } -- cgit v1.2.3