diff --git a/choose/choose.go b/choose/choose.go index 5d061f6..ad9ff1d 100644 --- a/choose/choose.go +++ b/choose/choose.go @@ -56,7 +56,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: return m, nil - case timeout.TimeoutMsg: + case timeout.TickTimeoutMsg: if msg.TimeoutValue <= 0 { m.quitting = true return m, tea.Quit @@ -158,7 +158,7 @@ func (m model) View() string { } var s strings.Builder - var timeoutStr string = "" + var timeoutStr string start, end := m.paginator.GetSliceBounds(len(m.items)) for i, item := range m.items[start:end] { diff --git a/confirm/command.go b/confirm/command.go index 56827e8..ae8041f 100644 --- a/confirm/command.go +++ b/confirm/command.go @@ -2,6 +2,7 @@ package confirm import ( "fmt" + "github.com/charmbracelet/gum/internal/exit" "os" "github.com/alecthomas/kong" @@ -31,7 +32,7 @@ func (o Options) Run() error { } if m.(model).aborted { - os.Exit(130) + os.Exit(exit.StatusAborted) } else if m.(model).confirmation { os.Exit(0) } else { diff --git a/confirm/confirm.go b/confirm/confirm.go index e759f46..768e728 100644 --- a/confirm/confirm.go +++ b/confirm/confirm.go @@ -67,7 +67,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.confirmation = true return m, tea.Quit } - case timeout.TimeoutMsg: + case timeout.TickTimeoutMsg: if msg.TimeoutValue <= 0 { m.quitting = true diff --git a/file/file.go b/file/file.go index 5793cc6..41fa151 100644 --- a/file/file.go +++ b/file/file.go @@ -104,7 +104,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case readDirMsg: m.files = msg - case timeout.TimeoutMsg: + case timeout.TickTimeoutMsg: if msg.TimeoutValue <= 0 { m.quitting = true m.aborted = true diff --git a/filter/filter.go b/filter/filter.go index 3d5f51c..5c7a4fe 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -136,7 +136,7 @@ func (m model) View() string { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { - case timeout.TimeoutMsg: + case timeout.TickTimeoutMsg: if msg.TimeoutValue <= 0 { m.quitting = true m.aborted = true diff --git a/input/input.go b/input/input.go index 9d74a8d..6080f3c 100644 --- a/input/input.go +++ b/input/input.go @@ -35,7 +35,7 @@ func (m model) View() string { if m.quitting { return "" } - var timeStr string = "" + var timeStr string if m.hasTimeout { timeStr = timeout.TimeoutStr(m.timeout) } @@ -49,7 +49,7 @@ func (m model) View() string { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { - case timeout.TimeoutMsg: + case timeout.TickTimeoutMsg: if msg.TimeoutValue <= 0 { m.quitting = true m.aborted = true diff --git a/pager/pager.go b/pager/pager.go index b0e62e4..3079cd0 100644 --- a/pager/pager.go +++ b/pager/pager.go @@ -32,7 +32,7 @@ func (m model) Init() tea.Cmd { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { - case timeout.TimeoutMsg: + case timeout.TickTimeoutMsg: if msg.TimeoutValue <= 0 { return m, tea.Quit } diff --git a/spin/spin.go b/spin/spin.go index c0de339..145b962 100644 --- a/spin/spin.go +++ b/spin/spin.go @@ -80,7 +80,7 @@ func (m model) Init() tea.Cmd { ) } func (m model) View() string { - var str string = "" + var str string if m.hasTimeout { str = timeout.TimeoutStr(m.timeout) } @@ -95,7 +95,7 @@ func (m model) View() string { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { - case timeout.TimeoutMsg: + case timeout.TickTimeoutMsg: if msg.TimeoutValue <= 0 { m.status = 130 return m, tea.Quit diff --git a/timeout/options.go b/timeout/options.go index 971e91e..f0c35a9 100644 --- a/timeout/options.go +++ b/timeout/options.go @@ -6,28 +6,28 @@ import ( "time" ) -// CmdOptions Common Timeout Option +// CmdOptions Common Timeout Option. type CmdOptions struct { Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"` } -// HasTimeout checks for a given timeout parameter +// HasTimeout checks for a given timeout parameter. func (o CmdOptions) HasTimeout() (hasTimeout bool) { return o.Timeout > 0 } -// Tick interval +// Tick interval. const tickInterval = time.Second -// TimeoutMsg will be dispatched for every tick. +// TickTimeoutMsg will be dispatched for every tick. // Containing current timeout value -// and optional parameter to be used when handling the timeout msg -type TimeoutMsg struct { +// and optional parameter to be used when handling the timeout msg. +type TickTimeoutMsg struct { TimeoutValue time.Duration Data interface{} } -// Init Start Timeout ticker using with timeout in seconds and optional data +// Init Start Timeout ticker using with timeout in seconds and optional data. func Init(timeout time.Duration, data interface{}) tea.Cmd { if timeout > 0 { return Tick(timeout, data) @@ -35,14 +35,14 @@ func Init(timeout time.Duration, data interface{}) tea.Cmd { return nil } -// Start ticker +// Start ticker. func Tick(timeoutValue time.Duration, data interface{}) tea.Cmd { return tea.Tick(tickInterval, func(time.Time) tea.Msg { // every tick checks if the timeout needs to be decremented // and send as message if timeoutValue >= 0 { timeoutValue -= tickInterval - return TimeoutMsg{ + return TickTimeoutMsg{ TimeoutValue: timeoutValue, Data: data, } @@ -51,6 +51,7 @@ func Tick(timeoutValue time.Duration, data interface{}) tea.Cmd { }) } +// TimeoutStr produce Timeout String to be rendered. func TimeoutStr(timeout time.Duration) string { return fmt.Sprintf(" (%d)", Max(0, int(timeout.Seconds()))) }