mirror of
https://github.com/charmbracelet/gum
synced 2024-06-28 02:00:07 +02:00
refactor: linter issues
This commit is contained in:
parent
d00b8dcdd1
commit
c01f6acfee
|
@ -56,7 +56,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
return m, nil
|
return m, nil
|
||||||
case timeout.TimeoutMsg:
|
case timeout.TickTimeoutMsg:
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
m.quitting = true
|
m.quitting = true
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
@ -158,7 +158,7 @@ func (m model) View() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var s strings.Builder
|
var s strings.Builder
|
||||||
var timeoutStr string = ""
|
var timeoutStr string
|
||||||
|
|
||||||
start, end := m.paginator.GetSliceBounds(len(m.items))
|
start, end := m.paginator.GetSliceBounds(len(m.items))
|
||||||
for i, item := range m.items[start:end] {
|
for i, item := range m.items[start:end] {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package confirm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/charmbracelet/gum/internal/exit"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/alecthomas/kong"
|
"github.com/alecthomas/kong"
|
||||||
|
@ -31,7 +32,7 @@ func (o Options) Run() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.(model).aborted {
|
if m.(model).aborted {
|
||||||
os.Exit(130)
|
os.Exit(exit.StatusAborted)
|
||||||
} else if m.(model).confirmation {
|
} else if m.(model).confirmation {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
m.confirmation = true
|
m.confirmation = true
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
case timeout.TimeoutMsg:
|
case timeout.TickTimeoutMsg:
|
||||||
|
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
m.quitting = true
|
m.quitting = true
|
||||||
|
|
|
@ -104,7 +104,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case readDirMsg:
|
case readDirMsg:
|
||||||
m.files = msg
|
m.files = msg
|
||||||
case timeout.TimeoutMsg:
|
case timeout.TickTimeoutMsg:
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
m.quitting = true
|
m.quitting = true
|
||||||
m.aborted = true
|
m.aborted = true
|
||||||
|
|
|
@ -136,7 +136,7 @@ func (m model) View() string {
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case timeout.TimeoutMsg:
|
case timeout.TickTimeoutMsg:
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
m.quitting = true
|
m.quitting = true
|
||||||
m.aborted = true
|
m.aborted = true
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (m model) View() string {
|
||||||
if m.quitting {
|
if m.quitting {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
var timeStr string = ""
|
var timeStr string
|
||||||
if m.hasTimeout {
|
if m.hasTimeout {
|
||||||
timeStr = timeout.TimeoutStr(m.timeout)
|
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) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case timeout.TimeoutMsg:
|
case timeout.TickTimeoutMsg:
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
m.quitting = true
|
m.quitting = true
|
||||||
m.aborted = true
|
m.aborted = true
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (m model) Init() tea.Cmd {
|
||||||
|
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case timeout.TimeoutMsg:
|
case timeout.TickTimeoutMsg:
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (m model) Init() tea.Cmd {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
var str string = ""
|
var str string
|
||||||
if m.hasTimeout {
|
if m.hasTimeout {
|
||||||
str = timeout.TimeoutStr(m.timeout)
|
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) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case timeout.TimeoutMsg:
|
case timeout.TickTimeoutMsg:
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
m.status = 130
|
m.status = 130
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
|
@ -6,28 +6,28 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdOptions Common Timeout Option
|
// CmdOptions Common Timeout Option.
|
||||||
type CmdOptions struct {
|
type CmdOptions struct {
|
||||||
Timeout time.Duration `help:"Timeout until command exits" default:"0" env:"GUM_CONFIRM_TIMEOUT"`
|
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) {
|
func (o CmdOptions) HasTimeout() (hasTimeout bool) {
|
||||||
return o.Timeout > 0
|
return o.Timeout > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tick interval
|
// Tick interval.
|
||||||
const tickInterval = time.Second
|
const tickInterval = time.Second
|
||||||
|
|
||||||
// TimeoutMsg will be dispatched for every tick.
|
// TickTimeoutMsg will be dispatched for every tick.
|
||||||
// Containing current timeout value
|
// Containing current timeout value
|
||||||
// and optional parameter to be used when handling the timeout msg
|
// and optional parameter to be used when handling the timeout msg.
|
||||||
type TimeoutMsg struct {
|
type TickTimeoutMsg struct {
|
||||||
TimeoutValue time.Duration
|
TimeoutValue time.Duration
|
||||||
Data interface{}
|
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 {
|
func Init(timeout time.Duration, data interface{}) tea.Cmd {
|
||||||
if timeout > 0 {
|
if timeout > 0 {
|
||||||
return Tick(timeout, data)
|
return Tick(timeout, data)
|
||||||
|
@ -35,14 +35,14 @@ func Init(timeout time.Duration, data interface{}) tea.Cmd {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start ticker
|
// Start ticker.
|
||||||
func Tick(timeoutValue time.Duration, data interface{}) tea.Cmd {
|
func Tick(timeoutValue time.Duration, data interface{}) tea.Cmd {
|
||||||
return tea.Tick(tickInterval, func(time.Time) tea.Msg {
|
return tea.Tick(tickInterval, func(time.Time) tea.Msg {
|
||||||
// every tick checks if the timeout needs to be decremented
|
// every tick checks if the timeout needs to be decremented
|
||||||
// and send as message
|
// and send as message
|
||||||
if timeoutValue >= 0 {
|
if timeoutValue >= 0 {
|
||||||
timeoutValue -= tickInterval
|
timeoutValue -= tickInterval
|
||||||
return TimeoutMsg{
|
return TickTimeoutMsg{
|
||||||
TimeoutValue: timeoutValue,
|
TimeoutValue: timeoutValue,
|
||||||
Data: data,
|
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 {
|
func TimeoutStr(timeout time.Duration) string {
|
||||||
return fmt.Sprintf(" (%d)", Max(0, int(timeout.Seconds())))
|
return fmt.Sprintf(" (%d)", Max(0, int(timeout.Seconds())))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue