4 "charm.land/bubbles/v2/key"
5 tea "charm.land/bubbletea/v2"
6 "charm.land/lipgloss/v2"
7 "github.com/charmbracelet/crush/internal/tui/components/dialogs"
8 "github.com/charmbracelet/crush/internal/tui/styles"
9 "github.com/charmbracelet/crush/internal/tui/util"
13 question = "Are you sure you want to quit?"
14 QuitDialogID dialogs.DialogID = "quit"
17// QuitDialog represents a confirmation dialog for quitting the application.
18type QuitDialog interface {
22type quitDialogCmp struct {
26 selectedNo bool // true if "No" button is selected
30// NewQuitDialog creates a new quit confirmation dialog.
31func NewQuitDialog() QuitDialog {
32 return &quitDialogCmp{
33 selectedNo: true, // Default to "No" for safety
34 keymap: DefaultKeymap(),
38func (q *quitDialogCmp) Init() tea.Cmd {
42// Update handles keyboard input for the quit dialog.
43func (q *quitDialogCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) {
44 switch msg := msg.(type) {
45 case tea.WindowSizeMsg:
47 q.wHeight = msg.Height
50 case key.Matches(msg, q.keymap.LeftRight, q.keymap.Tab):
51 q.selectedNo = !q.selectedNo
53 case key.Matches(msg, q.keymap.EnterSpace):
57 return q, util.CmdHandler(dialogs.CloseDialogMsg{})
58 case key.Matches(msg, q.keymap.Yes):
60 case key.Matches(msg, q.keymap.No, q.keymap.Close):
61 return q, util.CmdHandler(dialogs.CloseDialogMsg{})
67// View renders the quit dialog with Yes/No buttons.
68func (q *quitDialogCmp) View() string {
69 t := styles.CurrentTheme()
70 baseStyle := t.S().Base
71 yesStyle := t.S().Text
75 noStyle = noStyle.Foreground(t.White).Background(t.Secondary)
76 yesStyle = yesStyle.Background(t.BgSubtle)
78 yesStyle = yesStyle.Foreground(t.White).Background(t.Secondary)
79 noStyle = noStyle.Background(t.BgSubtle)
82 const horizontalPadding = 3
83 yesButton := yesStyle.PaddingLeft(horizontalPadding).Underline(true).Render("Y") +
84 yesStyle.PaddingRight(horizontalPadding).Render("ep!")
85 noButton := noStyle.PaddingLeft(horizontalPadding).Underline(true).Render("N") +
86 noStyle.PaddingRight(horizontalPadding).Render("ope")
88 buttons := baseStyle.Width(lipgloss.Width(question)).Align(lipgloss.Right).Render(
89 lipgloss.JoinHorizontal(lipgloss.Center, yesButton, " ", noButton),
92 content := baseStyle.Render(
93 lipgloss.JoinVertical(
101 quitDialogStyle := baseStyle.
103 Border(lipgloss.RoundedBorder()).
104 BorderForeground(t.BorderFocus)
106 return quitDialogStyle.Render(content)
109func (q *quitDialogCmp) Position() (int, int) {
113 col -= (lipgloss.Width(question) + 4) / 2
118func (q *quitDialogCmp) ID() dialogs.DialogID {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list