From af8701225a83e0521b6f5e5c68aab6b4f0809749 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 30 Jun 2022 00:17:26 +0530 Subject: added confirmation message and color coding when setting anime status --- mal/status.go | 24 ++++++------------------ ui/status.go | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/mal/status.go b/mal/status.go index 4a581df..c3866eb 100644 --- a/mal/status.go +++ b/mal/status.go @@ -21,36 +21,24 @@ package mal import ( "fmt" "os" + a "github.com/MikunoNaka/MAL2Go/v2/user/anime" + m "github.com/MikunoNaka/MAL2Go/v2/user/manga" ) -func SetAnimeStatus(animeId int, status string) { +func SetAnimeStatus(animeId int, status string) a.UpdateResponse { resp, err := userAnimeClient.SetStatus(animeId, status) if err != nil { fmt.Println("Error while parsing status:", err.Error()) os.Exit(1) } - // TODO: do something with resp - fmt.Println(resp) - - // not needed with MAL2Go v2.... probably - // if resp.Error != "" { - // fmt.Println("MyAnimeList reported error on setting anime status", resp.Error, resp.Message) - // os.Exit(1) - // } + return resp } -func SetMangaStatus(mangaId int, status string) { +func SetMangaStatus(mangaId int, status string) m.UpdateResponse { resp, err := userMangaClient.SetStatus(mangaId, status) if err != nil { fmt.Println("Error while parsing status:", err.Error()) os.Exit(1) } - // TODO: do something with resp - fmt.Println(resp) - - // not needed with MAL2Go v2.... probably - // if resp.Error != "" { - // fmt.Println("MyAnimeList reported error on setting manga status", resp.Error, resp.Message) - // os.Exit(1) - // } + return resp } diff --git a/ui/status.go b/ui/status.go index 09fd3d0..2b3894a 100644 --- a/ui/status.go +++ b/ui/status.go @@ -33,6 +33,24 @@ type StatusOption struct { Status string } +// to print dropped in red color, etc +func getColorCodeByStatus(status string) string { + switch status { + case "watching", "reading": + return "\x1b[32m" + case "completed": + return "\x1b[34m" + case "on_hold": + return "\x1b[33m" + case "dropped": + return "\x1b[31m" + case "plan_to_watch", "plan_to_read": + return "\x1b[36m" + default: + return "" + } +} + func AnimeStatusMenu(anime a.Anime) { options := []StatusOption { {"Watching", "watching"}, @@ -85,7 +103,8 @@ func AnimeStatusMenu(anime a.Anime) { os.Exit(1) } - mal.SetAnimeStatus(anime.Id, options[res].Status) + resp := mal.SetAnimeStatus(anime.Id, options[res].Status) + fmt.Println("Set \x1b[35m" + anime.Title + "\x1b[0m status to " + getColorCodeByStatus(resp.Status) + resp.Status + "\x1b[0m") } func MangaStatusMenu(manga m.Manga) { @@ -140,5 +159,6 @@ func MangaStatusMenu(manga m.Manga) { os.Exit(1) } - mal.SetMangaStatus(manga.Id, options[res].Status) + resp := mal.SetMangaStatus(manga.Id, options[res].Status) + fmt.Println("Set \x1b[35m" + manga.Title + "\x1b[0m status to " + getColorCodeByStatus(resp.Status) + resp.Status + "\x1b[0m") } -- cgit v1.2.3