package ui import ( tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" ) func (m *Model) updateConfirm(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) { c := m.confirm if c.typeToConf != "" { switch msg.String() { case "esc": m.confirm = nil return m, nil case "enter": if c.input == c.typeToConf { cmd := c.onConfirm() m.confirm = nil return m, cmd } return m, nil case "backspace": if len(c.input) > 0 { c.input = c.input[:len(c.input)-1] } return m, nil default: if len(msg.Text) > 0 { c.input += msg.Text } return m, nil } } switch msg.String() { case "y", "enter": cmd := c.onConfirm() m.confirm = nil return m, cmd case "n", "esc": m.confirm = nil return m, nil } return m, nil } func (m *Model) viewConfirm() string { c := m.confirm style := m.styles.Modal if c.danger { style = m.styles.ModalDanger } w := m.modalWrapWidth() lines := []string{m.styles.ModalTitle.Render(c.title), lipgloss.Wrap(c.body, w, ""), ""} if c.typeToConf != "" { lines = append(lines, "Type "+c.typeToConf+" to confirm:", "> "+c.input) } else { lines = append(lines, m.styles.Help.Render("y/enter confirm • n/esc cancel")) } return style.Render(lipgloss.JoinVertical(lipgloss.Left, lines...)) }