diff --git a/filter/command.go b/filter/command.go index f02c988..7fae0c5 100644 --- a/filter/command.go +++ b/filter/command.go @@ -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) } diff --git a/filter/filter.go b/filter/filter.go index 79fa619..146fbf6 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -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": diff --git a/main.go b/main.go index ddd9aa6..d2b3744 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "runtime/debug" "github.com/alecthomas/kong" @@ -54,5 +55,8 @@ func main() { "defaultUnderline": "false", }, ) - _ = ctx.Run() + if err := ctx.Run(); err != nil { + fmt.Println(err) + os.Exit(1) + } }