35 lines
581 B
Plaintext
35 lines
581 B
Plaintext
func (m model) Init() tea.Cmd {
|
|
return nil
|
|
}
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
|
|
case tea.KeyMsg:
|
|
switch msg.String() {
|
|
case "ctrl+c", "q":
|
|
return m, tea.Quit
|
|
case "up", "k":
|
|
if m.cursor > 0 {
|
|
m.cursor--
|
|
}
|
|
case "down", "j":
|
|
if m.cursor < len(m.choices)-1 {
|
|
m.cursor++
|
|
}
|
|
case "enter", " ":
|
|
_, ok := m.selected[m.cursor]
|
|
if ok {
|
|
delete(m.selected, m.cursor)
|
|
} else {
|
|
m.selected[m.cursor] = struct{}{}
|
|
}
|
|
}
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (m model) View() string {
|
|
return // ...
|
|
}
|