forked from charmbracelet/huh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymap.go
104 lines (94 loc) Β· 3.67 KB
/
keymap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package huh
import "github.com/charmbracelet/bubbles/key"
// KeyMap is the keybindings to navigate the form.
type KeyMap struct {
Quit key.Binding
Input InputKeyMap
Text TextKeyMap
Select SelectKeyMap
MultiSelect MultiSelectKeyMap
Note NoteKeyMap
Confirm ConfirmKeyMap
}
// InputKeyMap is the keybindings for input fields.
type InputKeyMap struct {
Next key.Binding
Prev key.Binding
}
// TextKeyMap is the keybindings for text fields.
type TextKeyMap struct {
Next key.Binding
Prev key.Binding
NewLine key.Binding
Editor key.Binding
}
// SelectKeyMap is the keybindings for select fields.
type SelectKeyMap struct {
Next key.Binding
Prev key.Binding
Up key.Binding
Down key.Binding
Filter key.Binding
SetFilter key.Binding
ClearFilter key.Binding
}
// MultiSelectKeyMap is the keybindings for multi-select fields.
type MultiSelectKeyMap struct {
Next key.Binding
Prev key.Binding
Up key.Binding
Down key.Binding
Toggle key.Binding
}
// NoteKeyMap is the keybindings for note fields.
type NoteKeyMap struct {
Next key.Binding
Prev key.Binding
}
// ConfirmKeyMap is the keybindings for confirm fields.
type ConfirmKeyMap struct {
Next key.Binding
Prev key.Binding
Toggle key.Binding
}
// NewDefaultKeyMap returns a new default keymap.
func NewDefaultKeyMap() *KeyMap {
return &KeyMap{
Quit: key.NewBinding(key.WithKeys("ctrl+c")),
Input: InputKeyMap{
Next: key.NewBinding(key.WithKeys("enter", "tab"), key.WithHelp("enter", "next")),
Prev: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")),
},
Text: TextKeyMap{
Next: key.NewBinding(key.WithKeys("tab", "enter"), key.WithHelp("enter", "next")),
Prev: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")),
NewLine: key.NewBinding(key.WithKeys("alt+enter", "ctrl+j"), key.WithHelp("alt+enter / ctrl+j", "new line")),
Editor: key.NewBinding(key.WithKeys("ctrl+e"), key.WithHelp("ctrl+e", "open editor")),
},
Select: SelectKeyMap{
Next: key.NewBinding(key.WithKeys("enter", "tab"), key.WithHelp("enter", "select")),
Prev: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")),
Up: key.NewBinding(key.WithKeys("up", "k", "ctrl+k", "ctrl+p"), key.WithHelp("β", "up")),
Down: key.NewBinding(key.WithKeys("down", "j", "ctrl+j", "ctrl+n"), key.WithHelp("β", "down")),
Filter: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "filter")),
SetFilter: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "set filter"), key.WithDisabled()),
ClearFilter: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "clear filter"), key.WithDisabled()),
},
MultiSelect: MultiSelectKeyMap{
Next: key.NewBinding(key.WithKeys("enter", "tab"), key.WithHelp("enter", "confirm")),
Prev: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")),
Toggle: key.NewBinding(key.WithKeys(" ", "x"), key.WithHelp("x", "toggle")),
Up: key.NewBinding(key.WithKeys("up", "k", "ctrl+p"), key.WithHelp("β", "up")),
Down: key.NewBinding(key.WithKeys("down", "j", "ctrl+n"), key.WithHelp("β", "down")),
},
Note: NoteKeyMap{
Next: key.NewBinding(key.WithKeys("enter", "tab"), key.WithHelp("enter", "next")),
Prev: key.NewBinding(key.WithKeys("shift+tab")),
},
Confirm: ConfirmKeyMap{
Next: key.NewBinding(key.WithKeys("enter", "tab"), key.WithHelp("enter", "next")),
Prev: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")),
Toggle: key.NewBinding(key.WithKeys("h", "l", "right", "left"), key.WithHelp("β/β", "toggle")),
},
}
}