mirror of
https://github.com/charmbracelet/gum
synced 2024-06-05 15:22:17 +02:00
feat: ctrl+c / esc aborts action
This commit is contained in:
parent
c8e6b4a9d5
commit
832c4fc917
|
@ -29,7 +29,9 @@ func (o Options) Run() error {
|
||||||
return fmt.Errorf("unable to run confirm: %w", err)
|
return fmt.Errorf("unable to run confirm: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.(model).confirmation {
|
if m.(model).aborted {
|
||||||
|
os.Exit(130)
|
||||||
|
} else if m.(model).confirmation {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -23,6 +23,7 @@ type model struct {
|
||||||
affirmative string
|
affirmative string
|
||||||
negative string
|
negative string
|
||||||
quitting bool
|
quitting bool
|
||||||
|
aborted bool
|
||||||
hasTimeout bool
|
hasTimeout bool
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
|
||||||
|
@ -57,7 +58,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, nil
|
return m, nil
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "ctrl+c", "esc", "q", "n", "N":
|
case "ctrl+c", "esc":
|
||||||
|
m.confirmation = false
|
||||||
|
m.aborted = true
|
||||||
|
m.quitting = true
|
||||||
|
return m, tea.Quit
|
||||||
|
case "q", "n", "N":
|
||||||
m.confirmation = false
|
m.confirmation = false
|
||||||
m.quitting = true
|
m.quitting = true
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
Loading…
Reference in a new issue