fix: default timeout selection

This commit is contained in:
Maas Lalani 2023-02-27 19:15:28 -05:00
parent 6c9c1eb8eb
commit 8879049985
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
2 changed files with 11 additions and 9 deletions

View file

@ -14,15 +14,16 @@ import (
// action with an affirmative or negative answer.
func (o Options) Run() error {
m, err := tea.NewProgram(model{
affirmative: o.Affirmative,
negative: o.Negative,
confirmation: o.Default,
timeout: o.Timeout,
hasTimeout: o.Timeout > 0,
prompt: o.Prompt,
selectedStyle: o.SelectedStyle.ToLipgloss(),
unselectedStyle: o.UnselectedStyle.ToLipgloss(),
promptStyle: o.PromptStyle.ToLipgloss(),
affirmative: o.Affirmative,
negative: o.Negative,
confirmation: o.Default,
defaultSelection: o.Default,
timeout: o.Timeout,
hasTimeout: o.Timeout > 0,
prompt: o.Prompt,
selectedStyle: o.SelectedStyle.ToLipgloss(),
unselectedStyle: o.UnselectedStyle.ToLipgloss(),
promptStyle: o.PromptStyle.ToLipgloss(),
}, tea.WithOutput(os.Stderr)).Run()
if err != nil {

View file

@ -88,6 +88,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tickMsg:
if m.timeout <= 0 {
m.quitting = true
m.confirmation = m.defaultSelection
return m, tea.Quit
}
m.timeout -= tickInterval