Added esc to keys and changed error code to 130

This commit is contained in:
mikael 2023-03-20 10:32:32 +01:00 committed by Maas Lalani
parent 97feb1b4d0
commit d9a3dc5324
2 changed files with 8 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/alecthomas/kong" "github.com/alecthomas/kong"
"github.com/charmbracelet/bubbles/filepicker" "github.com/charmbracelet/bubbles/filepicker"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/gum/internal/exit"
"github.com/charmbracelet/gum/style" "github.com/charmbracelet/gum/style"
) )
@ -53,6 +54,9 @@ func (o Options) Run() error {
} }
m = tm.(model) m = tm.(model)
if m.aborted {
return exit.ErrAborted
}
if m.selectedPath == "" { if m.selectedPath == "" {
os.Exit(1) os.Exit(1)

View file

@ -20,6 +20,7 @@ import (
type model struct { type model struct {
filepicker filepicker.Model filepicker filepicker.Model
selectedPath string selectedPath string
aborted bool
quitting bool quitting bool
} }
@ -31,7 +32,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.String() { switch msg.String() {
case "ctrl+c", "q": case "ctrl+c", "q", "esc":
m.aborted = true
m.quitting = true
return m, tea.Quit return m, tea.Quit
} }
} }