-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymap.go
94 lines (77 loc) · 2.95 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
package keymap
import (
"github.com/charmbracelet/bubbles/key"
)
// KeyMap is a collection of all the key bindings used by the shell
//
// A [Default] is provided and will be used by the shell if no other KeyMap is provided
// when creating a new shell.
type KeyMap struct {
Up key.Binding // Up is a binding for the user to look back in their command history
Down key.Binding // Down is a binding for the user to look forward in their command history
Left key.Binding // Left is a binding for the user to move the cursor left
Right key.Binding // Right is a binding for the user to move the cursor right
ExecuteCommand key.Binding // ExecuteCommand is a binding for the user to execute the current command
// Cancel is a binding for the user to cancel their current command
//
// It's behaviour changes depending on what the user is doing:
//
// 1. If a command is being run, it will cancel the command's context
// 2. If the user is searching their command history, it will cancel the search
// 3. If the user has a partially typed in command, it will clear the input
// 4. If none of the above, it will exit the shell
Cancel key.Binding
SearchHistoryBackwards key.Binding // SearchHistoryBackwards is a binding for the user to search their command history backwards
SearchHistoryForwards key.Binding // SearchHistoryForwards is a binding for the user to search their command history forwards
AutoComplete key.Binding // AutoComplete is a binding for the user to autocomplete their current command or cycle through autocompletions
PreviousAutoComplete key.Binding // PreviousAutoComplete is a binding for the user to cycle through previous autocompletions
// Quit is the binding for the user to quit the shell no matter what they are doing
Quit key.Binding
}
// Default is the default keymap for the prompt
var Default = KeyMap{
Up: key.NewBinding(
key.WithKeys("up"),
key.WithHelp("↑", "history up"),
),
Down: key.NewBinding(
key.WithKeys("down"),
key.WithHelp("↓", "history down"),
),
Left: key.NewBinding(
key.WithKeys("left"),
key.WithHelp("←", "left"),
),
Right: key.NewBinding(
key.WithKeys("right"),
key.WithHelp("→", "right"),
),
ExecuteCommand: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "execute command"),
),
Cancel: key.NewBinding(
key.WithKeys("ctrl+c", "esc"),
key.WithHelp("ctrl+c/esc", "cancel"),
),
SearchHistoryBackwards: key.NewBinding(
key.WithKeys("ctrl+r"),
key.WithHelp("ctrl+r", "history search"),
),
SearchHistoryForwards: key.NewBinding(
key.WithKeys("ctrl+s"),
key.WithHelp("ctrl+s", "history search (forward)"),
),
AutoComplete: key.NewBinding(
key.WithKeys("tab"),
key.WithHelp("tab", "autocomplete"),
),
PreviousAutoComplete: key.NewBinding(
key.WithKeys("shift+tab"),
key.WithHelp("shift+tab", "previous autocomplete"),
),
Quit: key.NewBinding(
key.WithKeys("ctrl+d"),
key.WithHelp("ctrl+d", "quit"),
),
}