Commit 8e68c323d7

8e68c323d7a0198c771f2b64d1208a4ec6433d71

parent: 4ea62ea2c1

Unsigned

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

Fix: Dynamic select fr

Layout: unified · split

internal/selection_menu.go +66 −61
@@ -428,64 +428,69 @@ 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
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
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 the menu order from config
441 menuOrder := strings.Split(GetGlobalConfig().MenuOrder, ",")
442
443 // Add options in the specified order
444 for _, key := range menuOrder {
445 if value, exists := options[key]; exists {
446 orderedOptions = append(orderedOptions, SelectionOption{
447 Key: key,
448 Label: value,
449 })
450 }
451 }
452 } else {
453 // For other selections, maintain alphabetical order
454 for key, value := range options {
455 orderedOptions = append(orderedOptions, SelectionOption{
456 Key: key,
457 Label: value,
458 })
459 }
460 }
461
462 model := &Model{
463 options: options,
464 filteredKeys: orderedOptions,
465 addNewOption: addnewoption,
466 }
467
468 if addnewoption {
469 model.filteredKeys = append(model.filteredKeys, SelectionOption{
470 Label: "Add new anime",
471 Key: "add_new",
472 })
473 }
474
475 model.filteredKeys = append(model.filteredKeys, SelectionOption{
476 Label: "Quit",
477 Key: "-1",
478 })
479
480 p := tea.NewProgram(model)
481
482 finalModel, err := p.Run()
483 if err != nil {
484 return SelectionOption{}, err
485 }
486
487 finalSelectionModel, ok := finalModel.(*Model)
488 if !ok {
489 return SelectionOption{}, fmt.Errorf("unexpected model type")
490 }
491
492 if finalSelectionModel.selected < len(finalSelectionModel.filteredKeys) {
493 return finalSelectionModel.filteredKeys[finalSelectionModel.selected], nil
494 }
495 return SelectionOption{}, nil
496}