mirror of
https://github.com/charmbracelet/gum
synced 2024-06-15 20:15:08 +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
|
||||
|
||||
defaultSelection bool
|
||||
|
||||
// styles
|
||||
promptStyle lipgloss.Style
|
||||
selectedStyle lipgloss.Style
|
||||
|
@ -49,6 +51,7 @@ func (m model) Init() tea.Cmd {
|
|||
if m.timeout > 0 {
|
||||
return tick()
|
||||
}
|
||||
m.defaultSelection = m.confirmation
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -99,18 +102,27 @@ func (m model) View() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
var aff, neg, timeout string
|
||||
var aff, neg, timeout, affirmativeTimeout, negativeTimeout string
|
||||
|
||||
if m.hasTimeout {
|
||||
timeout = fmt.Sprintf(" (%d)", max(0, int(m.timeout.Seconds())))
|
||||
}
|
||||
|
||||
if m.confirmation {
|
||||
aff = m.selectedStyle.Render(m.affirmative + timeout)
|
||||
neg = m.unselectedStyle.Render(m.negative)
|
||||
// set timer based on defaultSelection
|
||||
if m.defaultSelection {
|
||||
affirmativeTimeout = m.affirmative + timeout
|
||||
negativeTimeout = m.negative
|
||||
} else {
|
||||
aff = m.unselectedStyle.Render(m.affirmative)
|
||||
neg = m.selectedStyle.Render(m.negative + timeout)
|
||||
affirmativeTimeout = m.affirmative
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue