aboutsummaryrefslogtreecommitdiff
path: root/ui/actions.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-06-15 00:08:39 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-06-15 00:08:39 +0530
commit028632de277704fe4576e732d4997daa70f25f60 (patch)
tree343137fc2b19cb7c9568324a9529218ca6065e49 /ui/actions.go
parent5ac21806f34a7c88d2685420d53cbd585f4b4f3d (diff)
added color coding and error handling + other visual appeal
Diffstat (limited to 'ui/actions.go')
-rw-r--r--ui/actions.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/ui/actions.go b/ui/actions.go
index 77afae7..7db5a96 100644
--- a/ui/actions.go
+++ b/ui/actions.go
@@ -20,35 +20,44 @@ package ui
import (
"strings"
- "log"
+ "fmt"
+ "os"
p "github.com/manifoldco/promptui"
- // mal "github.com/MikunoNaka/macli/mal"
+ a "github.com/MikunoNaka/MAL2Go/anime"
)
type Action struct {
Label string
Description string
- Method func(int)
+ Method func(a.Anime)
}
// only search animes probably only now
-func ActionMenu() func(animeId int) {
+func ActionMenu(animeIsAdded bool) func(a.Anime) {
// TODO: load promptLength from config
promptLength := 5
options := []Action {
{"Set Status", "Set status for an anime (watching, dropped, etc)", StatusMenu},
- {"Set Episodes", "Set number of episodes watched", StatusMenu},
+ {"Set Episodes", "Set number of episodes watched", EpisodeInput},
{"Set Score", "Set score", StatusMenu},
{"Set Rewatching", "Set if rewatching", StatusMenu},
{"Set Times Rewatched", "Set number of times rewatched", StatusMenu},
}
+ // if anime not in list
+ if animeIsAdded {
+ options = append(
+ options,
+ Action{"Delete Anime", "Delete Anime From Your MyAnimeList List.", StatusMenu},
+ )
+ }
+
template := &p.SelectTemplates {
Label: "{{ .Label }}",
Active: "{{ .Label | magenta }} {{ .Description | faint }}",
Inactive: "{{ .Label }}",
- Selected: "{{ .Label }}",
+ Selected: "{{ .Label | magenta }}",
Details: `
-------------------
{{ .Description }}
@@ -72,8 +81,8 @@ func ActionMenu() func(animeId int) {
res, _, err := prompt.Run()
if err != nil {
- log.Println(err)
- return nil
+ fmt.Println("Error running actions menu.", err.Error())
+ os.Exit(1)
}
return options[res].Method