Commit 5a8dd93470

5a8dd934702a28cadbdd855822c40e7cbc914139

parent: b08ed0902f

Unsigned

Wraient <wraient.911@gmail.com> · 2025-02-26 21:32 UTC

Chore: Update DynamicSelect function to remove bloated arg

Layout: unified · split

cmd/curd/main.go +1 −1
@@ -596,7 +596,7 @@ func main() {
596596 if userCurdConfig.NextEpisodePrompt {
597597 internal.CurdOut(fmt.Sprintf("Start next episode (%d)?", anime.Ep.Number))
598598
599 selectedOption, err := internal.DynamicSelect(map[string]string{"yes": "Yes"}, false)
599 selectedOption, err := internal.DynamicSelect(map[string]string{"yes": "Yes"})
600600 if err != nil {
601601 internal.ExitCurd(err)
602602 }
internal/curd.go +12 −9
@@ -230,7 +230,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User) {
230230 }
231231
232232 // Select update option
233 updateSelection, err := DynamicSelect(updateOptions, false)
233 updateSelection, err := DynamicSelect(updateOptions)
234234 if err != nil {
235235 Log(fmt.Sprintf("Failed to select update option: %v", err))
236236 ExitCurd(fmt.Errorf("Failed to select update option"))
@@ -342,7 +342,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User) {
342342 if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview {
343343 selectedAnime, err = DynamicSelectPreview(animeListMapPreview, false)
344344 } else {
345 selectedAnime, err = DynamicSelect(animeListMap, false)
345 selectedAnime, err = DynamicSelect(animeListMap)
346346 }
347347 if err != nil {
348348 Log(fmt.Sprintf("Failed to select anime: %v", err))
@@ -382,7 +382,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User) {
382382 }
383383 CurdOut(fmt.Sprintf("Current category: %s", currentStatus))
384384
385 categorySelection, err := DynamicSelect(categories, false)
385 categorySelection, err := DynamicSelect(categories)
386386 if err != nil {
387387 Log(fmt.Sprintf("Failed to select category: %v", err))
388388 ExitCurd(fmt.Errorf("Failed to select category"))
@@ -577,7 +577,7 @@ func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseA
577577 if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview {
578578 anilistSelectedOption, err = DynamicSelectPreview(animeMapPreview, false)
579579 } else {
580 anilistSelectedOption, err = DynamicSelect(animeMap, false)
580 anilistSelectedOption, err = DynamicSelect(animeMap)
581581 }
582582
583583 if anilistSelectedOption.Key == "-1" {
@@ -606,7 +606,7 @@ func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseA
606606 ClearScreen()
607607 CurdOut("Select which list to add the anime to:")
608608
609 categorySelection, err := DynamicSelect(categories, false)
609 categorySelection, err := DynamicSelect(categories)
610610 if err != nil {
611611 Log(fmt.Sprintf("Failed to select category: %v", err))
612612 ExitCurd(fmt.Errorf("Failed to select category"))
@@ -719,7 +719,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
719719
720720 // Select category using DynamicSelect
721721 var err error
722 categorySelection, err = DynamicSelect(categories, false)
722 categorySelection, err = DynamicSelect(categories)
723723 if err != nil {
724724 Log(fmt.Sprintf("Failed to select category: %v", err))
725725 ExitCurd(fmt.Errorf("Failed to select category"))
@@ -795,7 +795,10 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
795795 if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview {
796796 anilistSelectedOption, err = DynamicSelectPreview(animeListMapPreview, true)
797797 } else {
798 anilistSelectedOption, err = DynamicSelect(animeListMap, true)
798 // Add "Add new anime" option to the map
799 animeListMap["add_new"] = "Add new anime"
800
801 anilistSelectedOption, err = DynamicSelect(animeListMap)
799802 }
800803 if err != nil {
801804 Log(fmt.Sprintf("Error selecting anime: %v", err))
@@ -860,7 +863,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
860863 // If unable to get Allanime id automatically get manually
861864 if anime.AllanimeId == "" {
862865 CurdOut("Failed to automatically select anime")
863 selectedAllanimeAnime, err := DynamicSelect(animeList, false)
866 selectedAllanimeAnime, err := DynamicSelect(animeList)
864867
865868 if selectedAllanimeAnime.Key == "-1" {
866869 ExitCurd(nil)
@@ -905,7 +908,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
905908 var err error
906909
907910 // Use rofi for selection
908 selectedOption, err = DynamicSelect(options, false)
911 selectedOption, err = DynamicSelect(options)
909912 if err != nil {
910913 Log("Error in selection: " + err.Error())
911914 ExitCurd(err)
internal/localTracking.go +1 −1
@@ -279,7 +279,7 @@ func WatchUntracked(userCurdConfig *CurdConfig) {
279279 }
280280
281281 // Select anime from search results
282 selectedAnime, err := DynamicSelect(animeList, false)
282 selectedAnime, err := DynamicSelect(animeList)
283283 if err != nil {
284284 Log(fmt.Sprintf("Failed to select anime: %v", err))
285285 ExitCurd(fmt.Errorf("Failed to select anime"))
internal/selection_menu.go +6 −19
@@ -363,7 +363,7 @@ func showCachedImagePreview(imageURL string) error {
363363 return nil
364364}
365365
366func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, error) {
366func RofiSelect(options map[string]string) (SelectionOption, error) {
367367 userCurdConfig := GetGlobalConfig()
368368 if userCurdConfig.StoragePath == "" {
369369 userCurdConfig.StoragePath = os.ExpandEnv("${HOME}/.local/share/curd")
@@ -378,13 +378,9 @@ func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, e
378378 // Sort the options alphabetically
379379 sort.Strings(optionsList)
380380
381 // Add "Add new anime" and "Quit" options
382 if addanimeopt {
383 optionsList = append(optionsList, "Add new anime", "Quit")
384 } else {
385 optionsList = append(optionsList, "Quit")
386 }
387
381 // Add "Quit" options
382 optionsList = append(optionsList, "Quit")
383
388384 // Join all options into a single string, separated by newlines
389385 optionsString := strings.Join(optionsList, "\n")
390386
@@ -409,8 +405,6 @@ func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, e
409405 switch selected {
410406 case "":
411407 return SelectionOption{}, fmt.Errorf("no selection made")
412 case "Add new anime":
413 return SelectionOption{Label: "Add new anime", Key: "add_new"}, nil
414408 case "Quit":
415409 return SelectionOption{Label: "Quit", Key: "-1"}, nil
416410 }
@@ -427,9 +421,9 @@ func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, e
427421}
428422
429423// DynamicSelect displays a simple selection prompt without extra features
430func DynamicSelect(options map[string]string, addnewoption bool) (SelectionOption, error) {
424func DynamicSelect(options map[string]string) (SelectionOption, error) {
431425 if GetGlobalConfig().RofiSelection {
432 return RofiSelect(options, addnewoption)
426 return RofiSelect(options)
433427 }
434428
435429 // Create a slice to maintain order
@@ -462,15 +456,8 @@ func DynamicSelect(options map[string]string, addnewoption bool) (SelectionOptio
462456 model := &Model{
463457 options: options,
464458 filteredKeys: orderedOptions,
465 addNewOption: addnewoption,
466459 }
467460
468 if addnewoption {
469 model.filteredKeys = append(model.filteredKeys, SelectionOption{
470 Label: "Add new anime",
471 Key: "add_new",
472 })
473 }
474461
475462 model.filteredKeys = append(model.filteredKeys, SelectionOption{
476463 Label: "Quit",