-
Notifications
You must be signed in to change notification settings - Fork 11
/
keymap.go
54 lines (45 loc) 路 1.21 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
package ghrepository
import (
"fmt"
teakey "github.com/charmbracelet/bubbles/key"
pkgconfig "github.com/termkit/gama/pkg/config"
)
type keyMap struct {
Refresh teakey.Binding
LaunchTab teakey.Binding
SwitchTab teakey.Binding
}
func (k keyMap) ShortHelp() []teakey.Binding {
return []teakey.Binding{k.SwitchTab, k.Refresh, k.LaunchTab}
}
func (k keyMap) FullHelp() [][]teakey.Binding {
return [][]teakey.Binding{
{k.SwitchTab},
{k.Refresh},
{k.LaunchTab},
}
}
var keys = func() keyMap {
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}
var tabSwitch = fmt.Sprintf("%s | %s", cfg.Shortcuts.SwitchTabLeft, cfg.Shortcuts.SwitchTabRight)
return keyMap{
Refresh: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Refresh),
teakey.WithHelp(cfg.Shortcuts.Refresh, "Refresh list"),
),
LaunchTab: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Enter),
teakey.WithHelp(cfg.Shortcuts.Enter, "Launch the selected option"),
),
SwitchTab: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp(tabSwitch, "switch tab"),
),
}
}()
func (m *ModelGithubRepository) ViewHelp() string {
return m.Help.View(m.Keys)
}