mirror of
https://github.com/charmbracelet/gum
synced 2024-06-10 09:42:16 +02:00
fix(input): ctrl+c exit status 130
This commit is contained in:
parent
d324abeab5
commit
0baa0b98bd
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue