Skip to content

Commit

Permalink
feat: allow confirm negative to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed May 1, 2024
1 parent 147e30b commit 1a310fe
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions field_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ func (c *Confirm) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch msg := msg.(type) {
case tea.KeyMsg:

c.err = nil

switch {
case key.Matches(msg, c.keymap.Toggle):
if c.negative == "" {
break
}
v := !*c.value
*c.value = v
case key.Matches(msg, c.keymap.Prev):
Expand Down Expand Up @@ -182,19 +183,21 @@ func (c *Confirm) View() string {
sb.WriteString("\n")
}

if *c.value {
sb.WriteString(lipgloss.JoinHorizontal(
lipgloss.Center,
styles.FocusedButton.Render(c.affirmative),
styles.BlurredButton.Render(c.negative),
))
var negative string
var affirmative string
if c.negative != "" {
if *c.value {
affirmative = styles.FocusedButton.Render(c.affirmative)
negative = styles.BlurredButton.Render(c.negative)
} else {
affirmative = styles.BlurredButton.Render(c.affirmative)
negative = styles.FocusedButton.Render(c.negative)
}
} else {
sb.WriteString(lipgloss.JoinHorizontal(
lipgloss.Center,
styles.BlurredButton.Render(c.affirmative),
styles.FocusedButton.Render(c.negative),
))
affirmative = styles.FocusedButton.Render(c.affirmative)
}

sb.WriteString(lipgloss.JoinHorizontal(lipgloss.Center, affirmative, negative))
return styles.Base.Render(sb.String())
}

Expand Down

0 comments on commit 1a310fe

Please sign in to comment.