diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-08-06 09:58:16 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-08-06 09:58:16 +0530 |
commit | 3d23ed955d11651bd9bacda02070b8d13b6922a1 (patch) | |
tree | bd059a01f9dbefbbf49471d64d8082feccae76da /ui/episodes.go | |
parent | da51d5d32c6a7795278539eaf994975c7776e296 (diff) |
added volumes command
Diffstat (limited to 'ui/episodes.go')
-rw-r--r-- | ui/episodes.go | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/ui/episodes.go b/ui/episodes.go index e6ac976..b4137ed 100644 --- a/ui/episodes.go +++ b/ui/episodes.go @@ -44,6 +44,13 @@ func CreateChapterUpdateConfirmationMessage(title string, chNum, prevChNum int) return fmt.Sprintf("\x1b[35m%s\x1b[0m Chapters Read :: \x1b[1;36m%d\x1b[0m", title, chNum) } +func CreateVolumeUpdateConfirmationMessage(title string, volNum, prevVolNum int) string { + if prevVolNum >= 0 { + return fmt.Sprintf("\x1b[35m%s\x1b[0m Volumes Read :: \x1b[1;33m%d\x1b[0m -> \x1b[1;36m%d\x1b[0m", title, prevVolNum, volNum) + } + return fmt.Sprintf("\x1b[35m%s\x1b[0m Volumes Read :: \x1b[1;36m%d\x1b[0m", title, volNum) +} + func EpisodeInput(anime a.Anime) { epWatchedNum := anime.MyListStatus.EpWatched epTotalNum := anime.NumEpisodes @@ -107,5 +114,38 @@ func ChapterInput(manga m.Manga) { } resp := mal.SetChapters(manga.Id, chReadNum, res) - fmt.Println(CreateEpisodeUpdateConfirmationMessage(manga.Title, resp.ChaptersRead, chReadNum)) + fmt.Println(CreateChapterUpdateConfirmationMessage(manga.Title, resp.ChaptersRead, chReadNum)) +} + +func VolumeInput(manga m.Manga) { + volReadNum := manga.MyListStatus.VolumesRead + volTotalNum := manga.NumVolumes + + validate := func(input string) error { + if _, err := strconv.ParseFloat(input, 64); err != nil { + return errors.New("Input must be a number.") + } + return nil + } + + template := &p.PromptTemplates { + Valid: "\x1b[0m{{ . | magenta }}", + Invalid: "\x1b[0m{{ . | magenta }}\x1b[31m", + Success: "{{ . | cyan }}", + } + + prompt := p.Prompt { + Label: fmt.Sprintf("Set Volume Number (%d/%d read): ", volReadNum, volTotalNum), + Templates: template, + Validate: validate, + } + + res, err := prompt.Run() + if err != nil { + fmt.Println("Error Running volume input Prompt.", err.Error()) + os.Exit(1) + } + + resp := mal.SetVolumes(manga.Id, volReadNum, res) + fmt.Println(CreateVolumeUpdateConfirmationMessage(manga.Title, resp.VolumesRead, volReadNum)) } |