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}
80
81func DefaultArgumentsDialogKeyMap() ArgumentsDialogKeyMap {
82 return ArgumentsDialogKeyMap{
83 Confirm: key.NewBinding(
84 key.WithKeys("enter"),
85 key.WithHelp("enter", "confirm"),
86 ),
87
88 Next: key.NewBinding(
89 key.WithKeys("tab", "down"),
90 key.WithHelp("tab/↓", "next"),
91 ),
92 Previous: key.NewBinding(
93 key.WithKeys("shift+tab", "up"),
94 key.WithHelp("shift+tab/↑", "previous"),
95 ),
96 }
97}
98
99// KeyBindings implements layout.KeyMapProvider
100func (k ArgumentsDialogKeyMap) KeyBindings() []key.Binding {
101 return []key.Binding{
102 k.Confirm,
103 k.Next,
104 k.Previous,
105 }
106}
107
108// FullHelp implements help.KeyMap.
109func (k ArgumentsDialogKeyMap) FullHelp() [][]key.Binding {
110 m := [][]key.Binding{}
111 slice := k.KeyBindings()
112 for i := 0; i < len(slice); i += 4 {
113 end := min(i+4, len(slice))
114 m = append(m, slice[i:end])
115 }
116 return m
117}
118
119// ShortHelp implements help.KeyMap.
120func (k ArgumentsDialogKeyMap) ShortHelp() []key.Binding {
121 return []key.Binding{
122 k.Confirm,
123 k.Next,
124 k.Previous,
125 }
126}