1package status
2
3import (
4 "github.com/charmbracelet/bubbles/v2/key"
5 "github.com/opencode-ai/opencode/internal/tui/layout"
6)
7
8type KeyMap struct {
9 Tab,
10 Commands,
11 Help key.Binding
12}
13
14func DefaultKeyMap(tabHelp string) KeyMap {
15 return KeyMap{
16 Tab: key.NewBinding(
17 key.WithKeys("tab"),
18 key.WithHelp("tab", tabHelp),
19 ),
20 Commands: key.NewBinding(
21 key.WithKeys("ctrl+p"),
22 key.WithHelp("ctrl+p", "commands"),
23 ),
24 Help: key.NewBinding(
25 key.WithKeys("ctrl+?", "ctrl+_", "ctrl+/"),
26 key.WithHelp("ctrl+?", "more"),
27 ),
28 }
29}
30
31// FullHelp implements help.KeyMap.
32func (k KeyMap) FullHelp() [][]key.Binding {
33 m := [][]key.Binding{}
34 slice := layout.KeyMapToSlice(k)
35 for i := 0; i < len(slice); i += 4 {
36 end := min(i+4, len(slice))
37 m = append(m, slice[i:end])
38 }
39 return m
40}
41
42// ShortHelp implements help.KeyMap.
43func (k KeyMap) ShortHelp() []key.Binding {
44 return []key.Binding{
45 k.Tab,
46 k.Commands,
47 k.Help,
48 }
49}