From 1cac547f4aa9d15a56281c4b5a9db5e8f3d97c47 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 4 Jul 2022 02:20:19 +0530 Subject: added anime info with searching --- ui/search.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/search.go b/ui/search.go index 8e6ac0d..baea6f1 100644 --- a/ui/search.go +++ b/ui/search.go @@ -32,14 +32,64 @@ import ( func AnimeSearch(label, searchString string) a.Anime { animes := mal.SearchAnime(searchString) + for i, anime := range animes { + animes[i].DurationSeconds = anime.DurationSeconds / 60 + + /* I cant find a way to add functions to the details template + * So I am formatting the studios as one string + * and setting as the first studio name. pretty hacky. */ + if len(anime.Studios) > 0 { + var studiosFormatted string + for j, studio := range anime.Studios { + studiosFormatted = studiosFormatted + studio.Name + // setting other studio names as "" + animes[i].Studios[j].Name = "" + if j != len(anime.Studios) - 1 { + studiosFormatted = studiosFormatted + ", " + } + } + animes[i].Studios[0].Name = studiosFormatted + } + + var ratingFormatted string + switch anime.Rating { + case "g": + ratingFormatted = "G - All Ages" + case "pg": + ratingFormatted = "PG - Children" + case "pg_13": + ratingFormatted = "PG13 - Teens 13 and Older" + case "r": + ratingFormatted = "R - 17+ (violence & profanity)" + case "r+": + ratingFormatted = "R+ - Profanity & Mild Nudity" + case "rx": + ratingFormatted = "Rx - Hentai" + default: + ratingFormatted = anime.Rating + } + animes[i].Rating = ratingFormatted + } + template := &p.SelectTemplates { Label: "{{ . }}", Active: "{{ .Title | magenta }}", Inactive: "{{ .Title }}", Selected: "{{ .Title | blue }}", + // TODO: format and maybe color code details Details: ` --------- {{ .Title }} ---------- -More Details To Be Added Later +{{ "Number of Episodes:" | blue | bold }} {{ .NumEpisodes }} +{{ "English Title:" | blue | bold }} {{ .AltTitles.En }} +{{ "Japanese Title:" | blue | bold }} {{ .AltTitles.Ja }} +{{ "Original Run:" | blue | bold }} {{ .StartDate }} - {{ .EndDate }} ({{ .StartSeason.Name }} {{ .StartSeason.Year }}) +{{ "Mean Score:" | blue | bold }} {{ .MeanScore }} +{{ "Rank:" | blue | bold }} {{ .Rank }} +{{ "Type:" | blue | bold }} {{ .MediaType }} +{{ "Status:" | blue | bold }} {{ .Status }} +{{ "Average Duration:" | blue | bold }} {{ .DurationSeconds }} minutes +{{ "Rating:" | blue | bold }} {{ .Rating }} +{{ "Studios:" | blue | bold }} {{ range .Studios }}{{ .Name }}{{ end }} `, } -- cgit v1.2.3