mirror of
https://github.com/charmbracelet/gum
synced 2024-06-27 09:40:06 +02:00
fix(confirm): ensure timer is located at fixed selection
This commit is contained in:
parent
8c99083115
commit
02591074e4
|
@ -29,6 +29,8 @@ type model struct {
|
||||||
|
|
||||||
confirmation bool
|
confirmation bool
|
||||||
|
|
||||||
|
defaultSelection bool
|
||||||
|
|
||||||
// styles
|
// styles
|
||||||
promptStyle lipgloss.Style
|
promptStyle lipgloss.Style
|
||||||
selectedStyle lipgloss.Style
|
selectedStyle lipgloss.Style
|
||||||
|
@ -49,6 +51,7 @@ func (m model) Init() tea.Cmd {
|
||||||
if m.timeout > 0 {
|
if m.timeout > 0 {
|
||||||
return tick()
|
return tick()
|
||||||
}
|
}
|
||||||
|
m.defaultSelection = m.confirmation
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,18 +102,27 @@ func (m model) View() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var aff, neg, timeout string
|
var aff, neg, timeout, affirmativeTimeout, negativeTimeout string
|
||||||
|
|
||||||
if m.hasTimeout {
|
if m.hasTimeout {
|
||||||
timeout = fmt.Sprintf(" (%d)", max(0, int(m.timeout.Seconds())))
|
timeout = fmt.Sprintf(" (%d)", max(0, int(m.timeout.Seconds())))
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.confirmation {
|
// set timer based on defaultSelection
|
||||||
aff = m.selectedStyle.Render(m.affirmative + timeout)
|
if m.defaultSelection {
|
||||||
neg = m.unselectedStyle.Render(m.negative)
|
affirmativeTimeout = m.affirmative + timeout
|
||||||
|
negativeTimeout = m.negative
|
||||||
} else {
|
} else {
|
||||||
aff = m.unselectedStyle.Render(m.affirmative)
|
affirmativeTimeout = m.affirmative
|
||||||
neg = m.selectedStyle.Render(m.negative + timeout)
|
negativeTimeout = m.negative + timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.confirmation {
|
||||||
|
aff = m.selectedStyle.Render(affirmativeTimeout)
|
||||||
|
neg = m.unselectedStyle.Render(negativeTimeout)
|
||||||
|
} else {
|
||||||
|
aff = m.unselectedStyle.Render(affirmativeTimeout)
|
||||||
|
neg = m.selectedStyle.Render(negativeTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the option is intentionally empty, do not show it.
|
// If the option is intentionally empty, do not show it.
|
||||||
|
|
Loading…
Reference in a new issue