4 "charm.land/bubbles/v2/key"
5 tea "charm.land/bubbletea/v2"
6 "charm.land/lipgloss/v2"
7 "github.com/charmbracelet/crush/internal/ui/common"
10// QuitDialogID is the identifier for the quit dialog.
11const QuitDialogID = "quit"
13// QuitDialogKeyMap represents key bindings for the quit dialog.
14type QuitDialogKeyMap struct {
23// DefaultQuitKeyMap returns the default key bindings for the quit dialog.
24func DefaultQuitKeyMap() QuitDialogKeyMap {
25 return QuitDialogKeyMap{
26 LeftRight: key.NewBinding(
27 key.WithKeys("left", "right"),
28 key.WithHelp("←/→", "switch options"),
30 EnterSpace: key.NewBinding(
31 key.WithKeys("enter", " "),
32 key.WithHelp("enter/space", "confirm"),
35 key.WithKeys("y", "Y", "ctrl+c"),
36 key.WithHelp("y/Y/ctrl+c", "yes"),
39 key.WithKeys("n", "N"),
40 key.WithHelp("n/N", "no"),
44 key.WithHelp("tab", "switch options"),
46 Close: key.NewBinding(
47 key.WithKeys("esc", "alt+esc"),
48 key.WithHelp("esc", "cancel"),
53// Quit represents a confirmation dialog for quitting the application.
56 keyMap QuitDialogKeyMap
57 selectedNo bool // true if "No" button is selected
60// NewQuit creates a new quit confirmation dialog.
61func NewQuit(com *common.Common) *Quit {
64 keyMap: DefaultQuitKeyMap(),
70// ID implements [Model].
71func (*Quit) ID() string {
75// Update implements [Model].
76func (q *Quit) Update(msg tea.Msg) (Dialog, tea.Cmd) {
77 switch msg := msg.(type) {
80 case key.Matches(msg, q.keyMap.LeftRight, q.keyMap.Tab):
81 q.selectedNo = !q.selectedNo
83 case key.Matches(msg, q.keyMap.EnterSpace):
88 case key.Matches(msg, q.keyMap.Yes):
90 case key.Matches(msg, q.keyMap.No, q.keyMap.Close):
98// View implements [Model].
99func (q *Quit) View() string {
100 const question = "Are you sure you want to quit?"
101 baseStyle := q.com.Styles.Base
102 buttonOpts := []common.ButtonOpts{
103 {Text: "Yep!", Selected: !q.selectedNo, Padding: 3},
104 {Text: "Nope", Selected: q.selectedNo, Padding: 3},
106 buttons := common.ButtonGroup(q.com.Styles, buttonOpts, " ")
107 content := baseStyle.Render(
108 lipgloss.JoinVertical(
116 return q.com.Styles.BorderFocus.Render(content)
119// ShortHelp implements [help.KeyMap].
120func (q *Quit) ShortHelp() []key.Binding {
121 return []key.Binding{
127// FullHelp implements [help.KeyMap].
128func (q *Quit) FullHelp() [][]key.Binding {
129 return [][]key.Binding{
130 {q.keyMap.LeftRight, q.keyMap.EnterSpace, q.keyMap.Yes, q.keyMap.No},
131 {q.keyMap.Tab, q.keyMap.Close},
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