mirror of
https://github.com/charmbracelet/gum.git
synced 2024-09-11 06:16:03 +03:00
fix(choose): ctrl+c aborts with exit 130
This commit is contained in:
parent
f0106b51ae
commit
5c6453b07c
@ -32,6 +32,7 @@ type model struct {
|
||||
limit int
|
||||
numSelected int
|
||||
paginator paginator.Model
|
||||
aborted bool
|
||||
|
||||
// styles
|
||||
cursorStyle lipgloss.Style
|
||||
@ -71,11 +72,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.index = clamp(m.index-m.height, 0, len(m.items)-1)
|
||||
m.paginator.PrevPage()
|
||||
case "ctrl+c":
|
||||
m.aborted = true
|
||||
m.quitting = true
|
||||
// Ctrl+C should unselect all items
|
||||
for i := range m.items {
|
||||
m.items[i].selected = false
|
||||
}
|
||||
return m, tea.Quit
|
||||
case " ", "x":
|
||||
if m.limit == 1 {
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/charmbracelet/bubbles/paginator"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/exit"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
@ -64,7 +65,7 @@ func (o Options) Run() error {
|
||||
pager.UseJKKeys = false
|
||||
pager.UsePgUpPgDownKeys = false
|
||||
|
||||
m, err := tea.NewProgram(model{
|
||||
tm, err := tea.NewProgram(model{
|
||||
height: o.Height,
|
||||
cursor: o.Cursor,
|
||||
selectedPrefix: o.SelectedPrefix,
|
||||
@ -78,9 +79,14 @@ func (o Options) Run() error {
|
||||
selectedItemStyle: o.SelectedItemStyle.ToLipgloss(),
|
||||
}, tea.WithOutput(os.Stderr)).StartReturningModel()
|
||||
|
||||
m := tm.(model)
|
||||
if m.aborted {
|
||||
return exit.ErrAborted
|
||||
}
|
||||
|
||||
var s strings.Builder
|
||||
|
||||
for _, item := range m.(model).items {
|
||||
for _, item := range m.items {
|
||||
if item.selected {
|
||||
s.WriteString(item.text)
|
||||
s.WriteRune('\n')
|
||||
|
Loading…
Reference in New Issue
Block a user