Commit 4ea62ea2c1

4ea62ea2c145752a527c5fa3c7d7eb6e55dac7e3

parent: 97ec259891

Unsigned

Wraient <wraient.911@gmail.com> · 2025-02-22 20:14 UTC

Fix: Dynamic select

Layout: unified · split

internal/selection_menu.go +61 −48
@@ -428,51 +428,64 @@ func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, e
428428
429429// DynamicSelect displays a simple selection prompt without extra features
430430func DynamicSelect(options map[string]string, addnewoption bool) (SelectionOption, error) {
431 if GetGlobalConfig().RofiSelection {
432 return RofiSelect(options, addnewoption)
433 }
434
435 // Create a slice to maintain order
436 var orderedOptions []SelectionOption
437 for key, value := range options {
438 orderedOptions = append(orderedOptions, SelectionOption{
439 Key: key,
440 Label: value,
441 })
442 }
443
444 model := &Model{
445 options: options,
446 filteredKeys: orderedOptions,
447 addNewOption: addnewoption,
448 }
449
450 if addnewoption {
451 model.filteredKeys = append(model.filteredKeys, SelectionOption{
452 Label: "Add new anime",
453 Key: "add_new",
454 })
455 }
456
457 model.filteredKeys = append(model.filteredKeys, SelectionOption{
458 Label: "Quit",
459 Key: "-1",
460 })
461
462 p := tea.NewProgram(model)
463
464 finalModel, err := p.Run()
465 if err != nil {
466 return SelectionOption{}, err
467 }
468
469 finalSelectionModel, ok := finalModel.(*Model)
470 if !ok {
471 return SelectionOption{}, fmt.Errorf("unexpected model type")
472 }
473
474 if finalSelectionModel.selected < len(finalSelectionModel.filteredKeys) {
475 return finalSelectionModel.filteredKeys[finalSelectionModel.selected], nil
476 }
477 return SelectionOption{}, nil
478}
431 if GetGlobalConfig().RofiSelection {
432 return RofiSelect(options, addnewoption)
433 }
434
435 // Create a slice to maintain order
436 var orderedOptions []SelectionOption
437
438 // If this is a category selection (contains menu items), use the ordered keys
439 if _, hasMenu := options["ALL"]; hasMenu {
440 // Get ordered keys from the options map
441 for key, value := range options {
442 orderedOptions = append(orderedOptions, SelectionOption{
443 Key: key,
444 Label: value,
445 })
446 }
447 } else {
448 // For other selections, maintain alphabetical order
449 for key, value := range options {
450 orderedOptions = append(orderedOptions, SelectionOption{
451 Key: key,
452 Label: value,
453 })
454 }
455 }
456
457 model := &Model{
458 options: options,
459 filteredKeys: orderedOptions,
460 addNewOption: addnewoption,
461 }
462
463 if addnewoption {
464 model.filteredKeys = append(model.filteredKeys, SelectionOption{
465 Label: "Add new anime",
466 Key: "add_new",
467 })
468 }
469
470 model.filteredKeys = append(model.filteredKeys, SelectionOption{
471 Label: "Quit",
472 Key: "-1",
473 })
474
475 p := tea.NewProgram(model)
476
477 finalModel, err := p.Run()
478 if err != nil {
479 return SelectionOption{}, err
480 }
481
482 finalSelectionModel, ok := finalModel.(*Model)
483 if !ok {
484 return SelectionOption{}, fmt.Errorf("unexpected model type")
485 }
486
487 if finalSelectionModel.selected < len(finalSelectionModel.filteredKeys) {
488 return finalSelectionModel.filteredKeys[finalSelectionModel.selected], nil
489 }
490 return SelectionOption{}, nil
491}
\ No newline at end of file