aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-03 22:57:06 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-03 22:57:06 +0530
commitbd0da056a9f4c1246ad5a980b1c824b7382478cf (patch)
tree3aedc5be2f841f8492b176cc77dcc95087caeede
parent8494b2933908d54d0c64ca08d877efe4e3d8d7b3 (diff)
dynamically handling prompt length, search length, offset, etc
-rw-r--r--mal/mal.go14
-rw-r--r--mal/search.go8
-rw-r--r--ui/actions.go10
-rw-r--r--ui/episodes.go4
-rw-r--r--ui/search.go8
-rw-r--r--ui/ui.go21
6 files changed, 38 insertions, 27 deletions
diff --git a/mal/mal.go b/mal/mal.go
index 9c55bcf..2bc1672 100644
--- a/mal/mal.go
+++ b/mal/mal.go
@@ -27,11 +27,15 @@ import (
um "github.com/MikunoNaka/MAL2Go/v2/user/manga"
)
-var animeClient a.Client
-var mangaClient m.Client
-var userClient u.Client
-var userAnimeClient ua.Client
-var userMangaClient um.Client
+var (
+ animeClient a.Client
+ mangaClient m.Client
+ userClient u.Client
+ userAnimeClient ua.Client
+ userMangaClient um.Client
+
+ SearchLength, SearchOffset int
+)
// init() would kill the program prematurely on `macli login` command
func Init() {
diff --git a/mal/search.go b/mal/search.go
index 8fee461..5add67f 100644
--- a/mal/search.go
+++ b/mal/search.go
@@ -26,11 +26,9 @@ import (
)
func SearchAnime(searchString string) []a.Anime {
- // TODO: read limit, offset from flags
- limit, offset := 10, 0
fields := []string{"title", "id", "my_list_status"}
- res, err := animeClient.SearchAnime(searchString, limit, offset, fields)
+ res, err := animeClient.SearchAnime(searchString, SearchLength, SearchOffset, fields)
if err != nil {
fmt.Println("MyAnimeList reported error while searching:", err.Error())
os.Exit(1)
@@ -40,11 +38,9 @@ func SearchAnime(searchString string) []a.Anime {
}
func SearchManga(searchString string) []m.Manga {
- // TODO: read limit, offset from flags
- limit, offset := 10, 0
fields := []string{"title", "id", "my_list_status"}
- res, err := mangaClient.SearchManga(searchString, limit, offset, fields)
+ res, err := mangaClient.SearchManga(searchString, SearchLength, SearchOffset, fields)
if err != nil {
fmt.Println("MyAnimeList reported error while searching:", err.Error())
os.Exit(1)
diff --git a/ui/actions.go b/ui/actions.go
index b6bbf16..7831fe4 100644
--- a/ui/actions.go
+++ b/ui/actions.go
@@ -41,9 +41,6 @@ type MangaAction struct {
}
func AnimeActionMenu(animeIsAdded bool) func(a.Anime) {
- // TODO: load promptLength from config
- promptLength := 5
-
options := []AnimeAction {
{"Set Status", "Set status for an anime (watching, dropped, etc)", AnimeStatusMenu},
{"Set Episodes", "Set number of episodes watched", EpisodeInput},
@@ -83,7 +80,7 @@ func AnimeActionMenu(animeIsAdded bool) func(a.Anime) {
Items: options,
Templates: template,
Searcher: searcher,
- Size: promptLength,
+ Size: PromptLength,
}
res, _, err := prompt.Run()
@@ -96,9 +93,6 @@ func AnimeActionMenu(animeIsAdded bool) func(a.Anime) {
}
func MangaActionMenu(mangaIsAdded bool) func(m.Manga) {
- // TODO: load promptLength from config
- promptLength := 5
-
options := []MangaAction {
{"Set Status", "Set status for a manga (reading, dropped, etc)", MangaStatusMenu},
{"Set Chapters", "Set number of chapters read", ChapterInput},
@@ -138,7 +132,7 @@ func MangaActionMenu(mangaIsAdded bool) func(m.Manga) {
Items: options,
Templates: template,
Searcher: searcher,
- Size: promptLength,
+ Size: PromptLength,
}
res, _, err := prompt.Run()
diff --git a/ui/episodes.go b/ui/episodes.go
index 3b5bbe8..f8ad28a 100644
--- a/ui/episodes.go
+++ b/ui/episodes.go
@@ -31,11 +31,11 @@ import (
// very short name I know
func CreateEpisodeUpdateConfirmationMessage(title string, prevEpNum, epNum int) string {
- return fmt.Sprintf("\x1b[35m%s\x1b[0m Episodes Updated :: \x1b[1;33m%d\x1b[0m -> \x1b[1;36m%d\x1b[0m", title, prevEpNum, epNum)
+ return fmt.Sprintf("\x1b[35m%s\x1b[0m Episodes Watched :: \x1b[1;33m%d\x1b[0m -> \x1b[1;36m%d\x1b[0m", title, prevEpNum, epNum)
}
func CreateChapterUpdateConfirmationMessage(title string, prevChNum, chNum int) string {
- return fmt.Sprintf("\x1b[35m%s\x1b[0m Chapters Updated :: \x1b[1;33m%d\x1b[0m -> \x1b[1;36m%d\x1b[0m", title, prevChNum, chNum)
+ return fmt.Sprintf("\x1b[35m%s\x1b[0m Chapters Read :: \x1b[1;33m%d\x1b[0m -> \x1b[1;36m%d\x1b[0m", title, prevChNum, chNum)
}
func EpisodeInput(anime a.Anime) {
diff --git a/ui/search.go b/ui/search.go
index c62006a..7ea045a 100644
--- a/ui/search.go
+++ b/ui/search.go
@@ -30,8 +30,6 @@ import (
// only search animes probably only now
func AnimeSearch(label, searchString string) a.Anime {
- // TODO: load promptLength from config
- promptLength := 5
animes := mal.SearchAnime(searchString)
template := &p.SelectTemplates {
@@ -57,7 +55,7 @@ More Details To Be Added Later
Items: animes,
Templates: template,
Searcher: searcher,
- Size: promptLength,
+ Size: PromptLength,
}
animeIndex, _, err := prompt.Run()
@@ -70,8 +68,6 @@ More Details To Be Added Later
}
func MangaSearch(label, searchString string) m.Manga {
- // TODO: load promptLength from config
- promptLength := 5
mangas := mal.SearchManga(searchString)
template := &p.SelectTemplates {
@@ -97,7 +93,7 @@ More Details To Be Added Later
Items: mangas,
Templates: template,
Searcher: searcher,
- Size: promptLength,
+ Size: PromptLength,
}
mangaIndex, _, err := prompt.Run()
diff --git a/ui/ui.go b/ui/ui.go
new file mode 100644
index 0000000..74bf0f3
--- /dev/null
+++ b/ui/ui.go
@@ -0,0 +1,21 @@
+/*
+macli - Unofficial CLI-Based MyAnimeList Client
+Copyright © 2022 Vidhu Kant Sharma <vidhukant@vidhukant.xyz>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package ui
+
+var PromptLength int