mirror of
https://github.com/charmbracelet/gum.git
synced 2024-08-17 02:00:46 +03:00
feat: ctrl-c & esc abort filtering
This commit is contained in:
parent
fd788a4dd9
commit
6538d726d1
@ -44,6 +44,9 @@ func (o Options) Run() error {
|
||||
tm, err := p.StartReturningModel()
|
||||
m := tm.(model)
|
||||
|
||||
if m.aborted {
|
||||
return fmt.Errorf("filter aborted")
|
||||
}
|
||||
if len(m.matches) > m.selected && m.selected >= 0 {
|
||||
fmt.Println(m.matches[m.selected].Str)
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ type model struct {
|
||||
selected int
|
||||
indicator string
|
||||
height int
|
||||
aborted bool
|
||||
quitting bool
|
||||
matchStyle lipgloss.Style
|
||||
textStyle lipgloss.Style
|
||||
@ -90,7 +91,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.height = msg.Height
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c", "esc", "enter":
|
||||
case "ctrl+c", "esc":
|
||||
m.aborted = true
|
||||
fallthrough
|
||||
case "enter":
|
||||
m.quitting = true
|
||||
return m, tea.Quit
|
||||
case "ctrl+n", "ctrl+j", "down":
|
||||
|
Loading…
Reference in New Issue
Block a user