1package commands
2
3import (
4 "github.com/charmbracelet/bubbles/v2/key"
5)
6
7type CommandsDialogKeyMap struct {
8 Select,
9 Next,
10 Previous,
11 Tab,
12 Close key.Binding
13}
14
15func DefaultCommandsDialogKeyMap() CommandsDialogKeyMap {
16 return CommandsDialogKeyMap{
17 Select: key.NewBinding(
18 key.WithKeys("enter", "ctrl+y"),
19 key.WithHelp("enter", "confirm"),
20 ),
21 Next: key.NewBinding(
22 key.WithKeys("down", "ctrl+n"),
23 key.WithHelp("↓", "next item"),
24 ),
25 Previous: key.NewBinding(
26 key.WithKeys("up", "ctrl+p"),
27 key.WithHelp("↑", "previous item"),
28 ),
29 Tab: key.NewBinding(
30 key.WithKeys("tab"),
31 key.WithHelp("tab", "switch selection"),
32 ),
33 Close: key.NewBinding(
34 key.WithKeys("esc", "alt+esc"),
35 key.WithHelp("esc", "cancel"),
36 ),
37 }
38}
39
40// KeyBindings implements layout.KeyMapProvider
41func (k CommandsDialogKeyMap) KeyBindings() []key.Binding {
42 return []key.Binding{
43 k.Select,
44 k.Next,
45 k.Previous,
46 k.Tab,
47 k.Close,
48 }
49}
50
51// FullHelp implements help.KeyMap.
52func (k CommandsDialogKeyMap) FullHelp() [][]key.Binding {
53 m := [][]key.Binding{}
54 slice := k.KeyBindings()
55 for i := 0; i < len(slice); i += 4 {
56 end := min(i+4, len(slice))
57 m = append(m, slice[i:end])
58 }
59 return m
60}
61
62// ShortHelp implements help.KeyMap.
63func (k CommandsDialogKeyMap) ShortHelp() []key.Binding {
64 return []key.Binding{
65 k.Tab,
66 key.NewBinding(
67 key.WithKeys("down", "up"),
68 key.WithHelp("↑↓", "choose"),
69 ),
70 k.Select,
71 k.Close,
72 }
73}
74
75type ArgumentsDialogKeyMap struct {
76 Confirm key.Binding
77 Next key.Binding
78 Previous key.Binding
79 Close key.Binding
80}
81
82func DefaultArgumentsDialogKeyMap() ArgumentsDialogKeyMap {
83 return ArgumentsDialogKeyMap{
84 Confirm: key.NewBinding(
85 key.WithKeys("enter"),
86 key.WithHelp("enter", "confirm"),
87 ),
88
89 Next: key.NewBinding(
90 key.WithKeys("tab", "down"),
91 key.WithHelp("tab/↓", "next"),
92 ),
93 Previous: key.NewBinding(
94 key.WithKeys("shift+tab", "up"),
95 key.WithHelp("shift+tab/↑", "previous"),
96 ),
97 Close: key.NewBinding(
98 key.WithKeys("esc", "alt+esc"),
99 key.WithHelp("esc", "cancel"),
100 ),
101 }
102}
103
104// KeyBindings implements layout.KeyMapProvider
105func (k ArgumentsDialogKeyMap) KeyBindings() []key.Binding {
106 return []key.Binding{
107 k.Confirm,
108 k.Next,
109 k.Previous,
110 k.Close,
111 }
112}
113
114// FullHelp implements help.KeyMap.
115func (k ArgumentsDialogKeyMap) FullHelp() [][]key.Binding {
116 m := [][]key.Binding{}
117 slice := k.KeyBindings()
118 for i := 0; i < len(slice); i += 4 {
119 end := min(i+4, len(slice))
120 m = append(m, slice[i:end])
121 }
122 return m
123}
124
125// ShortHelp implements help.KeyMap.
126func (k ArgumentsDialogKeyMap) ShortHelp() []key.Binding {
127 return []key.Binding{
128 k.Confirm,
129 k.Next,
130 k.Previous,
131 k.Close,
132 }
133}