diff --git a/input/command.go b/input/command.go index 4625a17..fc25a1f 100644 --- a/input/command.go +++ b/input/command.go @@ -7,6 +7,7 @@ import ( "github.com/alecthomas/kong" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/gum/internal/exit" "github.com/charmbracelet/gum/internal/stdin" "github.com/charmbracelet/gum/style" ) @@ -33,9 +34,18 @@ func (o Options) Run() error { i.EchoCharacter = '•' } - p := tea.NewProgram(model{i}, tea.WithOutput(os.Stderr)) - m, err := p.StartReturningModel() - fmt.Println(m.(model).textinput.Value()) + p := tea.NewProgram(model{ + textinput: i, + aborted: false, + }, tea.WithOutput(os.Stderr)) + tm, err := p.StartReturningModel() + m := tm.(model) + + if m.aborted { + os.Exit(exit.Aborted) + } + + fmt.Println(m.textinput.Value()) return err } diff --git a/input/input.go b/input/input.go index 294bfa9..6886148 100644 --- a/input/input.go +++ b/input/input.go @@ -13,7 +13,10 @@ import ( tea "github.com/charmbracelet/bubbletea" ) -type model struct{ textinput textinput.Model } +type model struct { + textinput textinput.Model + aborted bool +} func (m model) Init() tea.Cmd { return textinput.Blink } func (m model) View() string { return m.textinput.View() } @@ -21,7 +24,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch msg.Type { - case tea.KeyEscape, tea.KeyCtrlC, tea.KeyEnter: + case tea.KeyEscape, tea.KeyCtrlC: + m.aborted = true + fallthrough + case tea.KeyEnter: return m, tea.Quit } }