mirror of
https://github.com/charmbracelet/gum
synced 2024-06-27 01:30:06 +02:00
chore: Rename Timeout Option
This commit is contained in:
parent
559e244e12
commit
36c5ba5f1e
|
@ -60,6 +60,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
case timeout.TickTimeoutMsg:
|
||||
if msg.TimeoutValue <= 0 {
|
||||
m.quitting = true
|
||||
// If the user hasn't selected any items in a multi-select.
|
||||
// Then we select the item that they have pressed enter on. If they
|
||||
// have selected items, then we simply return them.
|
||||
if m.numSelected < 1 {
|
||||
m.items[m.index].selected = true
|
||||
}
|
||||
return m, tea.Quit
|
||||
}
|
||||
m.timeout = msg.TimeoutValue
|
||||
|
|
|
@ -2,7 +2,7 @@ package choose
|
|||
|
||||
import (
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Options is the customization options for the choose command.
|
||||
|
@ -20,5 +20,5 @@ type Options struct {
|
|||
CursorStyle style.Styles `embed:"" prefix:"cursor." set:"defaultForeground=212" envprefix:"GUM_CHOOSE_CURSOR_"`
|
||||
ItemStyle style.Styles `embed:"" prefix:"item." hidden:"" envprefix:"GUM_CHOOSE_ITEM_"`
|
||||
SelectedItemStyle style.Styles `embed:"" prefix:"selected." set:"defaultForeground=212" envprefix:"GUM_CHOOSE_SELECTED_"`
|
||||
TimeoutOptions timeout.Options // including timeout command options [Timeout,...]
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"` // including timeout command options [Timeout,...]
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func (o Options) Run() error {
|
|||
confirmation: o.Default,
|
||||
defvalue: o.Default,
|
||||
timeout: o.Timeout,
|
||||
hasTimeout: o.HasTimeout(),
|
||||
hasTimeout: o.Timeout > 0,
|
||||
prompt: o.Prompt,
|
||||
selectedStyle: o.SelectedStyle.ToLipgloss(),
|
||||
unselectedStyle: o.UnselectedStyle.ToLipgloss(),
|
||||
|
|
|
@ -2,7 +2,7 @@ package confirm
|
|||
|
||||
import (
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Options is the customization timeout for the confirm command.
|
||||
|
@ -16,5 +16,5 @@ type Options struct {
|
|||
SelectedStyle style.Styles `embed:"" prefix:"selected." help:"The style of the selected action" set:"defaultBackground=212" set:"defaultForeground=230" set:"defaultPadding=0 3" set:"defaultMargin=1 1" envprefix:"GUM_CONFIRM_SELECTED_"`
|
||||
//nolint:staticcheck
|
||||
UnselectedStyle style.Styles `embed:"" prefix:"unselected." help:"The style of the unselected action" set:"defaultBackground=235" set:"defaultForeground=254" set:"defaultPadding=0 3" set:"defaultMargin=1 1" envprefix:"GUM_CONFIRM_UNSELECTED_"`
|
||||
timeout.Options // including timeout command options [Timeout,...]
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func (o Options) Run() error {
|
|||
selectedStyle: o.SelectedStyle.ToLipgloss().Inline(true),
|
||||
fileSizeStyle: o.FileSizeStyle.ToLipgloss().Inline(true),
|
||||
timeout: o.Timeout,
|
||||
hasTimeout: o.HasTimeout(),
|
||||
hasTimeout: o.Timeout > 0,
|
||||
aborted: false,
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package file
|
|||
|
||||
import (
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Options are the options for the file command.
|
||||
|
@ -25,5 +25,5 @@ type Options struct {
|
|||
SelectedStyle style.Styles `embed:"" prefix:"selected." help:"The style to use for the selected item" set:"defaultBold=true" set:"defaultForeground=212" envprefix:"GUM_FILE_SELECTED_"`
|
||||
//nolint:staticcheck
|
||||
FileSizeStyle style.Styles `embed:"" prefix:"file-size." help:"The style to use for file sizes" set:"defaultWidth=8" set:"defaultAlign=right" set:"defaultForeground=240" envprefix:"GUM_FILE_FILE_SIZE_"`
|
||||
timeout.Options
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func (o Options) Run() error {
|
|||
reverse: o.Reverse,
|
||||
fuzzy: o.Fuzzy,
|
||||
timeout: o.Timeout,
|
||||
hasTimeout: o.HasTimeout(),
|
||||
hasTimeout: o.Timeout > 0,
|
||||
}, options...)
|
||||
|
||||
tm, err := p.Run()
|
||||
|
|
|
@ -2,7 +2,7 @@ package filter
|
|||
|
||||
import (
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Options is the customization options for the filter command.
|
||||
|
@ -26,5 +26,5 @@ type Options struct {
|
|||
Value string `help:"Initial filter value" default:"" env:"GUM_FILTER_VALUE"`
|
||||
Reverse bool `help:"Display from the bottom of the screen" env:"GUM_FILTER_REVERSE"`
|
||||
Fuzzy bool `help:"Enable fuzzy matching" default:"true" env:"GUM_FILTER_FUZZY" negatable:""`
|
||||
timeout.Options
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func (o Options) Run() error {
|
|||
header: o.Header,
|
||||
headerStyle: o.HeaderStyle.ToLipgloss(),
|
||||
timeout: o.Timeout,
|
||||
hasTimeout: o.HasTimeout(),
|
||||
hasTimeout: o.Timeout > 0,
|
||||
}, tea.WithOutput(os.Stderr))
|
||||
tm, err := p.Run()
|
||||
if err != nil {
|
||||
|
|
|
@ -36,16 +36,12 @@ func (m model) View() string {
|
|||
if m.quitting {
|
||||
return ""
|
||||
}
|
||||
var timeStr string
|
||||
if m.hasTimeout {
|
||||
timeStr = timeout.Str(m.timeout)
|
||||
}
|
||||
if m.header != "" {
|
||||
header := m.headerStyle.Render(m.header)
|
||||
return lipgloss.JoinVertical(lipgloss.Left, header, m.textinput.View()+" "+timeStr)
|
||||
return lipgloss.JoinVertical(lipgloss.Left, header, m.textinput.View())
|
||||
}
|
||||
|
||||
return timeStr + " " + m.textinput.View()
|
||||
return m.textinput.View()
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
|
|
@ -2,7 +2,7 @@ package input
|
|||
|
||||
import (
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Options are the customization options for the input.
|
||||
|
@ -17,5 +17,5 @@ type Options struct {
|
|||
Password bool `help:"Mask input characters" default:"false"`
|
||||
Header string `help:"Header value" default:"" env:"GUM_INPUT_HEADER"`
|
||||
HeaderStyle style.Styles `embed:"" prefix:"header." set:"defaultForeground=240" envprefix:"GUM_INPUT_HEADER_"`
|
||||
timeout.Options
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package pager
|
|||
|
||||
import (
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Options are the options for the pager.
|
||||
|
@ -14,5 +14,5 @@ type Options struct {
|
|||
ShowLineNumbers bool `help:"Show line numbers" default:"true"`
|
||||
LineNumberStyle style.Styles `embed:"" prefix:"line-number." help:"Style the line numbers" set:"defaultForeground=237" envprefix:"GUM_PAGER_LINE_NUMBER_"`
|
||||
SoftWrap bool `help:"Soft wrap lines" default:"false"`
|
||||
timeout.Options
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func (o Options) Run() error {
|
|||
command: o.Command,
|
||||
align: o.Align,
|
||||
timeout: o.Timeout,
|
||||
hasTimeout: o.HasTimeout(),
|
||||
hasTimeout: o.Timeout > 0,
|
||||
}
|
||||
p := tea.NewProgram(m, tea.WithOutput(os.Stderr))
|
||||
mm, err := p.Run()
|
||||
|
|
|
@ -2,7 +2,7 @@ package spin
|
|||
|
||||
import (
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Options is the customization options for the spin command.
|
||||
|
@ -15,5 +15,5 @@ type Options struct {
|
|||
Title string `help:"Text to display to user while spinning" default:"Loading..." env:"GUM_SPIN_TITLE"`
|
||||
TitleStyle style.Styles `embed:"" prefix:"title." envprefix:"GUM_SPIN_TITLE_"`
|
||||
Align string `help:"Alignment of spinner with regard to the title" short:"a" type:"align" enum:"left,right" default:"left" env:"GUM_SPIN_ALIGN"`
|
||||
timeout.Options
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
||||
}
|
||||
|
|
|
@ -7,16 +7,6 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// Options Common Timeout Option.
|
||||
type Options struct {
|
||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
||||
}
|
||||
|
||||
// HasTimeout checks for a given timeout parameter.
|
||||
func (o Options) HasTimeout() (hasTimeout bool) {
|
||||
return o.Timeout > 0
|
||||
}
|
||||
|
||||
// Tick interval.
|
||||
const tickInterval = time.Second
|
||||
|
||||
|
|
Loading…
Reference in a new issue