@@ -1,4 +1,4 @@
1−package dialog
1+package ui
4 "github.com/charmbracelet/bubbles/v2/key"
4 "github.com/charmbracelet/bubbles/v2/key"
@@ -6,27 +6,69 @@ import (
6 "github.com/charmbracelet/lipgloss/v2"
6 "github.com/charmbracelet/lipgloss/v2"
9+// QuitDialogKeyMap represents key bindings for the quit dialog.
10+type QuitDialogKeyMap struct {
19+// DefaultQuitKeyMap returns the default key bindings for the quit dialog.
20+func DefaultQuitKeyMap() QuitDialogKeyMap {
21+ return QuitDialogKeyMap{
22+ LeftRight: key.NewBinding(
23+ key.WithKeys("left", "right"),
24+ key.WithHelp("←/→", "switch options"),
26+ EnterSpace: key.NewBinding(
27+ key.WithKeys("enter", " "),
28+ key.WithHelp("enter/space", "confirm"),
31+ key.WithKeys("y", "Y", "ctrl+c"),
32+ key.WithHelp("y/Y/ctrl+c", "yes"),
35+ key.WithKeys("n", "N"),
36+ key.WithHelp("n/N", "no"),
40+ key.WithHelp("tab", "switch options"),
42+ Close: key.NewBinding(
43+ key.WithKeys("esc", "alt+esc"),
44+ key.WithHelp("esc", "cancel"),
9−// Quit represents a confirmation dialog for quitting the application.
49+// QuitDialog represents a confirmation dialog for quitting the application.
10−type Quit struct {
50+type QuitDialog struct {
11− keyMap QuitKeyMap
51+ com *Common
52+ keyMap QuitDialogKeyMap
12 selectedNo bool // true if "No" button is selected
53 selectedNo bool // true if "No" button is selected
15−// NewQuit creates a new quit confirmation dialog.
56+// NewQuitDialog creates a new quit confirmation dialog.
16−func NewQuit() *Quit {
57+func NewQuitDialog(com *Common) *QuitDialog {
17− q := &Quit{
58+ q := &QuitDialog{
18 keyMap: DefaultQuitKeyMap(),
60 keyMap: DefaultQuitKeyMap(),
23// ID implements [Model].
65// ID implements [Model].
24−func (*Quit) ID() string {
66+func (*QuitDialog) ID() string {
25 return "quit"
67 return "quit"
28// Update implements [Model].
70// Update implements [Model].
29−func (q *Quit) Update(msg tea.Msg) (Model, tea.Cmd) {
71+func (q *QuitDialog) Update(msg tea.Msg) (Dialog, tea.Cmd) {
30 switch msg := msg.(type) {
72 switch msg := msg.(type) {
31 case tea.KeyPressMsg:
73 case tea.KeyPressMsg:
@@ -49,19 +91,15 @@ func (q *Quit) Update(msg tea.Msg) (Model, tea.Cmd) {
51// View implements [Model].
93// View implements [Model].
52−func (q *Quit) View() string {
94+func (q *QuitDialog) View() string {
53 const question = "Are you sure you want to quit?"
95 const question = "Are you sure you want to quit?"
54−
96+ baseStyle := q.com.Styles.Base
55− baseStyle := lipgloss.NewStyle()
97+ yesStyle := q.com.Styles.ButtonSelected
56− yesStyle := lipgloss.NewStyle()
98+ noStyle := q.com.Styles.ButtonUnselected
59 if q.selectedNo {
100 if q.selectedNo {
60− noStyle = noStyle.Foreground(lipgloss.Color("15")).Background(lipgloss.Color("15"))
101+ noStyle = q.com.Styles.ButtonSelected
61− yesStyle = yesStyle.Background(lipgloss.Color("15"))
102+ yesStyle = q.com.Styles.ButtonUnselected
63− yesStyle = yesStyle.Foreground(lipgloss.Color("15")).Background(lipgloss.Color("15"))
64− noStyle = noStyle.Background(lipgloss.Color("15"))
67 const horizontalPadding = 3
105 const horizontalPadding = 3
@@ -83,16 +121,11 @@ func (q *Quit) View() string {
86− quitDialogStyle := baseStyle.
88− Border(lipgloss.RoundedBorder()).
89− BorderForeground(lipgloss.Color("15"))
91− return quitDialogStyle.Render(content)
124+ return q.com.Styles.BorderFocus.Render(content)
94// ShortHelp implements [help.KeyMap].
127// ShortHelp implements [help.KeyMap].
95−func (q *Quit) ShortHelp() []key.Binding {
128+func (q *QuitDialog) ShortHelp() []key.Binding {
96 return []key.Binding{
129 return []key.Binding{
97 q.keyMap.LeftRight,
130 q.keyMap.LeftRight,
98 q.keyMap.EnterSpace,
131 q.keyMap.EnterSpace,
@@ -100,7 +133,7 @@ func (q *Quit) ShortHelp() []key.Binding {
102// FullHelp implements [help.KeyMap].
135// FullHelp implements [help.KeyMap].
103−func (q *Quit) FullHelp() [][]key.Binding {
136+func (q *QuitDialog) FullHelp() [][]key.Binding {
104 return [][]key.Binding{
137 return [][]key.Binding{
105 {q.keyMap.LeftRight, q.keyMap.EnterSpace, q.keyMap.Yes, q.keyMap.No},
138 {q.keyMap.LeftRight, q.keyMap.EnterSpace, q.keyMap.Yes, q.keyMap.No},
106 {q.keyMap.Tab, q.keyMap.Close},
139 {q.keyMap.Tab, q.keyMap.Close},