diff options
Diffstat (limited to 'ui/episodes.go')
-rw-r--r-- | ui/episodes.go | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/ui/episodes.go b/ui/episodes.go index a2413bd..53c1cb9 100644 --- a/ui/episodes.go +++ b/ui/episodes.go @@ -20,64 +20,46 @@ package ui import ( "strconv" - "log" + "fmt" + "os" + "errors" "github.com/MikunoNaka/macli/mal" + a "github.com/MikunoNaka/MAL2Go/anime" + // m "github.com/MikunoNaka/MAL2Go/manga" p "github.com/manifoldco/promptui" ) -func EpisodeInput(animeId int) { +func EpisodeInput(anime a.Anime) { validate := func(input string) error { - _, err := strconv.ParseFloat(input, 64) - return err + if _, err := strconv.ParseFloat(input, 64); err != nil { + return errors.New("Input must be a number.") + } + return nil } template := &p.PromptTemplates { - Prompt: "{{ . }} ", - Valid: "{{ . }} ", - Invalid: "{{ . | red }} ", - Success: "{{ . }} ", + Valid: "\x1b[0m{{ . | magenta }}", + Invalid: "\x1b[0m{{ . | magenta }}\x1b[31m ", + Success: "{{ . | cyan }}", } prompt := p.Prompt { - // Label: "Set Episode Number: (Increment/Decrement With +1, -2, etc)", Label: "Set Episode Number: ", Templates: template, Validate: validate, } - res, err := prompt.Run() - if err != nil { - log.Println("Error Running EpisodeInput Prompt.", err) - return - } - - mal.SetEpisodes(animeId, res) -} - -func ChapterInput(mangaId int) { - validate := func(input string) error { - _, err := strconv.ParseFloat(input, 64) - return err - } - - template := &p.PromptTemplates { - Prompt: "{{ . }} ", - Valid: "{{ . }} ", - Invalid: "{{ . | red }} ", - Success: "{{ . }} ", - } - - prompt := p.Prompt { - Label: "Set Chapter Number: (Increment/Decrement With +1, -2, etc)", - Templates: template, - Validate: validate, + // print current episode number if any + epNum := anime.MyListStatus.EpWatched + if epNum != 0 { + fmt.Printf("\x1b[33mYou currently have watched %d episodes.\n\x1b[0m", epNum) } res, err := prompt.Run() if err != nil { - log.Println("Error Running ChapterInput Prompt.", err) - return + fmt.Println("Error Running episode input Prompt.", err.Error()) + os.Exit(1) } - mal.SetChapters(mangaId, res) + mal.SetEpisodes(anime.Id, res) } |