-
Notifications
You must be signed in to change notification settings - Fork 1
/
keys.go
103 lines (95 loc) · 2.64 KB
/
keys.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
package shared
import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
// nolint gochecknoglobals: used here on purpose
var boldText = lipgloss.NewStyle().Bold(true)
type KeyMap struct {
Tab key.Binding
ShiftTab key.Binding
Up key.Binding
Down key.Binding
PrevPage key.Binding
NextPage key.Binding
FocusRight key.Binding
FocusLeft key.Binding
Select key.Binding
Help key.Binding
HelpShort key.Binding
Quit key.Binding
}
func (k KeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Help, k.Quit, k.Tab, k.Select}
}
func (k KeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.HelpShort, k.Quit, k.Tab},
{k.Up, k.Down, k.PrevPage, k.NextPage},
{k.Select},
}
}
func (k KeyMap) ShortWithFocus() []key.Binding {
return []key.Binding{k.Help, k.Quit, k.Tab, k.FocusRight}
}
func (k KeyMap) FullWithFocus() [][]key.Binding {
return [][]key.Binding{
{k.HelpShort, k.Quit, k.Tab},
{k.Up, k.Down, k.PrevPage, k.NextPage},
{k.FocusLeft, k.FocusRight},
}
}
// GetKeyMaps returns all the shortcuts available.
func GetKeyMaps() KeyMap {
return KeyMap{
Tab: key.NewBinding(
key.WithKeys("tab"),
key.WithHelp(boldText.Render("tab"), "next tab"),
),
ShiftTab: key.NewBinding(
key.WithKeys("shift+tab"),
key.WithHelp(boldText.Render("Shift+tab"), "previous tab"),
),
Up: key.NewBinding(
key.WithKeys("up", "k"),
key.WithHelp(boldText.Render("↑/k"), "move up"),
),
Down: key.NewBinding(
key.WithKeys("down", "j"),
key.WithHelp(boldText.Render("↓/j"), "move down"),
),
PrevPage: key.NewBinding(
key.WithKeys("left", "h"),
key.WithHelp(boldText.Render("←/h"), "prev page"),
),
NextPage: key.NewBinding(
key.WithKeys("right", "l"),
key.WithHelp(boldText.Render("→/l"), "next page"),
),
FocusRight: key.NewBinding(
key.WithKeys(tea.KeyCtrlL.String(), tea.KeyCtrlRight.String()),
key.WithHelp(boldText.Render("Ctrl+→/Ctrl+l"), "focus right"),
),
FocusLeft: key.NewBinding(
key.WithKeys(tea.KeyCtrlH.String(), tea.KeyCtrlLeft.String()),
key.WithHelp(boldText.Render("Ctrl+←/Ctrl+h"), "focus left"),
),
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp(boldText.Render("?"), "full help"),
),
HelpShort: key.NewBinding(
key.WithKeys("?"),
key.WithHelp(boldText.Render("?"), "short help"),
),
Select: key.NewBinding(
key.WithKeys(tea.KeyEnter.String()),
key.WithHelp(boldText.Render("Enter"), "select item"),
),
Quit: key.NewBinding(
key.WithKeys("q", "esc", "ctrl+c"),
key.WithHelp(boldText.Render("q"), "quit"),
),
}
}