refactor: remove default value tranport using timeout Message

This commit is contained in:
Dieter Eickstaedt 2023-01-08 08:57:45 +01:00
parent 02d0bf4dbc
commit d00b8dcdd1

View file

@ -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
} }