Skip to content

Commit

Permalink
fix(file): handle ctrl+c
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Dec 6, 2024
1 parent b8cb2dc commit e56baf4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ import (
type keymap filepicker.KeyMap

var keyQuit = key.NewBinding(
key.WithKeys("esc", "q", "ctrl+c"),
key.WithKeys("esc", "q"),
key.WithHelp("esc", "close"),
)

var keyAbort = key.NewBinding(
key.WithKeys("ctrl+c"),
key.WithHelp("ctrl+c", "abort"),
)

func defaultKeymap() keymap {
km := filepicker.DefaultKeyMap()
km.Down.SetHelp("↓", "down")
Expand Down Expand Up @@ -76,11 +81,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
// TODO: should this handle q and esc differently than ctrl+c?
case key.Matches(msg, keyQuit):
case key.Matches(msg, keyAbort):
m.aborted = true
m.quitting = true
return m, tea.Quit
case key.Matches(msg, keyQuit):
m.quitting = true
return m, tea.Quit
}
case timeout.TickTimeoutMsg:
if msg.TimeoutValue <= 0 {
Expand Down

0 comments on commit e56baf4

Please sign in to comment.