Commit c3eba1630c
Unsigned
Layout: unified · split
internal/selection_menu.go +11 −8
| @@ -16,13 +16,13 @@ type SelectionOption struct { | |||
| 16 | 16 | ||
| 17 | // Model represents the application state for the selection prompt | 17 | // Model represents the application state for the selection prompt |
| 18 | type Model struct { | 18 | type Model struct { |
| 19 | options map[string]string | 19 | options map[string]string |
| 20 | filter string | 20 | filter string |
| 21 | filteredKeys []SelectionOption | 21 | filteredKeys []SelectionOption |
| 22 | selected int | 22 | selected int |
| 23 | terminalWidth int | 23 | terminalWidth int |
| 24 | terminalHeight int | 24 | terminalHeight int |
| 25 | scrollOffset int // Track the topmost visible item | 25 | scrollOffset int // Track the topmost visible item |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | // Init initializes the model | 28 | // Init initializes the model |
| @@ -44,7 +44,9 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |||
| 44 | case tea.KeyMsg: | 44 | case tea.KeyMsg: |
| 45 | switch msg.String() { | 45 | switch msg.String() { |
| 46 | case "ctrl+c", "q": | 46 | case "ctrl+c", "q": |
| 47 | return m, tea.Quit | 47 | // Return quit selection option instead of quitting the program |
| 48 | m.filteredKeys[m.selected] = SelectionOption{"quit", "-1"} | ||
| 49 | return m, tea.Quit // Properly exit the program | ||
| 48 | case "backspace": | 50 | case "backspace": |
| 49 | if len(m.filter) > 0 { | 51 | if len(m.filter) > 0 { |
| 50 | m.filter = m.filter[:len(m.filter)-1] | 52 | m.filter = m.filter[:len(m.filter)-1] |
| @@ -73,6 +75,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |||
| 73 | case "enter": | 75 | case "enter": |
| 74 | if m.filteredKeys[m.selected].Key == "add_new" { | 76 | if m.filteredKeys[m.selected].Key == "add_new" { |
| 75 | fmt.Println("Adding a new anime...") | 77 | fmt.Println("Adding a new anime...") |
| 78 | m.filteredKeys[m.selected] = SelectionOption{"add_new", "0"} | ||
| 76 | return m, tea.Quit | 79 | return m, tea.Quit |
| 77 | } | 80 | } |
| 78 | return m, tea.Quit | 81 | return m, tea.Quit |
| @@ -86,7 +89,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |||
| 86 | 89 | ||
| 87 | if updateFilter { | 90 | if updateFilter { |
| 88 | m.filterOptions() | 91 | m.filterOptions() |
| 89 | m.selected = 0 // Reset selection to the first item after filtering | 92 | m.selected = 0 // Reset selection to the first item after filtering |
| 90 | m.scrollOffset = 0 // Reset scrolling | 93 | m.scrollOffset = 0 // Reset scrolling |
| 91 | } | 94 | } |
| 92 | 95 | ||