-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymap.go
83 lines (77 loc) · 2.11 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
// Copyright 2024, Northwood Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package clihelpers
import "github.com/charmbracelet/bubbles/key"
// KeyBindings are the standard/default keybindings for the application.
var KeyBindings = KeyMap{
Up: key.NewBinding(
key.WithKeys("up", "k"),
key.WithHelp("↑/k", "move up"),
),
Down: key.NewBinding(
key.WithKeys("down", "j"),
key.WithHelp("↓/j", "move down"),
),
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle help"),
),
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "make selection"),
),
Quit: key.NewBinding(
key.WithKeys("q", "esc", "ctrl+c"),
key.WithHelp("q/esc", "quit"),
),
}
type (
// keyMap defines a set of keybindings. To work for help it must satisfy
// key.Map. It could also very easily be a map[string]key.Binding.
KeyMap struct {
Up key.Binding
Down key.Binding
Help key.Binding
Enter key.Binding
Quit key.Binding
}
)
// ShortHelp returns keybindings to be shown in the mini help view. It's part
// of the key.Map interface.
func (k KeyMap) ShortHelp() []key.Binding { // lint:allow_large_memory
// Implementing a model I have no control over.
return []key.Binding{
k.Help,
k.Enter,
k.Quit,
}
}
// FullHelp returns keybindings for the expanded help view. It's part of the
// key.Map interface.
func (k KeyMap) FullHelp() [][]key.Binding { // lint:allow_large_memory
// Implementing a model I have no control over.
return [][]key.Binding{
{ // first column
k.Up,
k.Down,
},
{ // second column
k.Help,
k.Quit,
},
{ // third column
k.Enter,
},
}
}