mirror of
https://github.com/charmbracelet/gum
synced 2024-06-20 06:25:08 +02:00
refactor: remove default value tranport using timeout Message
This commit is contained in:
parent
02d0bf4dbc
commit
d00b8dcdd1
|
@ -18,10 +18,6 @@ import (
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
type defaultVal struct {
|
|
||||||
Value bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
prompt string
|
prompt string
|
||||||
affirmative string
|
affirmative string
|
||||||
|
@ -39,7 +35,7 @@ type model struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
return timeout.Init(m.timeout, defaultVal{Value: m.confirmation})
|
return timeout.Init(m.timeout, m.defvalue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
@ -75,12 +71,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
|
||||||
if msg.TimeoutValue <= 0 {
|
if msg.TimeoutValue <= 0 {
|
||||||
m.quitting = true
|
m.quitting = true
|
||||||
if v, ok := msg.Data.(defaultVal); ok {
|
m.confirmation = m.defvalue
|
||||||
m.confirmation = v.Value
|
|
||||||
} else {
|
|
||||||
m.confirmation = false
|
|
||||||
}
|
|
||||||
|
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue