keys.go

 1package tui
 2
 3import (
 4	"github.com/charmbracelet/bubbles/v2/key"
 5	"github.com/opencode-ai/opencode/internal/tui/layout"
 6)
 7
 8type KeyMap struct {
 9	Logs          key.Binding
10	Quit          key.Binding
11	Help          key.Binding
12	SwitchSession key.Binding
13	Commands      key.Binding
14	FilePicker    key.Binding
15	Models        key.Binding
16	SwitchTheme   key.Binding
17}
18
19func DefaultKeyMap() KeyMap {
20	return KeyMap{
21		Logs: key.NewBinding(
22			key.WithKeys("ctrl+l"),
23			key.WithHelp("ctrl+l", "logs"),
24		),
25
26		Quit: key.NewBinding(
27			key.WithKeys("ctrl+c"),
28			key.WithHelp("ctrl+c", "quit"),
29		),
30
31		Help: key.NewBinding(
32			key.WithKeys("ctrl+_"),
33			key.WithHelp("ctrl+?", "toggle help"),
34		),
35
36		SwitchSession: key.NewBinding(
37			key.WithKeys("ctrl+s"),
38			key.WithHelp("ctrl+s", "switch session"),
39		),
40
41		Commands: key.NewBinding(
42			key.WithKeys("ctrl+k"),
43			key.WithHelp("ctrl+k", "commands"),
44		),
45		FilePicker: key.NewBinding(
46			key.WithKeys("ctrl+f"),
47			key.WithHelp("ctrl+f", "select files to upload"),
48		),
49		Models: key.NewBinding(
50			key.WithKeys("ctrl+o"),
51			key.WithHelp("ctrl+o", "model selection"),
52		),
53
54		SwitchTheme: key.NewBinding(
55			key.WithKeys("ctrl+t"),
56			key.WithHelp("ctrl+t", "switch theme"),
57		),
58	}
59}
60
61// FullHelp implements help.KeyMap.
62func (k KeyMap) FullHelp() [][]key.Binding {
63	m := [][]key.Binding{}
64	slice := layout.KeyMapToSlice(k)
65	for i := 0; i < len(slice); i += 4 {
66		end := min(i+4, len(slice))
67		m = append(m, slice[i:end])
68	}
69	return m
70}
71
72// ShortHelp implements help.KeyMap.
73func (k KeyMap) ShortHelp() []key.Binding {
74	return []key.Binding{}
75}