keys.go

 1package commands
 2
 3import (
 4	"github.com/charmbracelet/bubbles/v2/key"
 5	"github.com/opencode-ai/opencode/internal/tui/layout"
 6)
 7
 8type CommandsDialogKeyMap struct {
 9	Select   key.Binding
10	Next     key.Binding
11	Previous key.Binding
12}
13
14func DefaultCommandsDialogKeyMap() CommandsDialogKeyMap {
15	return CommandsDialogKeyMap{
16		Select: key.NewBinding(
17			key.WithKeys("enter", "tab", "ctrl+y"),
18			key.WithHelp("enter", "confirm"),
19		),
20		Next: key.NewBinding(
21			key.WithKeys("down", "ctrl+n"),
22			key.WithHelp("↓", "next item"),
23		),
24		Previous: key.NewBinding(
25			key.WithKeys("up", "ctrl+p"),
26			key.WithHelp("↑", "previous item"),
27		),
28	}
29}
30
31// FullHelp implements help.KeyMap.
32func (k CommandsDialogKeyMap) 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 CommandsDialogKeyMap) ShortHelp() []key.Binding {
44	return []key.Binding{
45		k.Select,
46		k.Next,
47		k.Previous,
48	}
49}
50
51type ArgumentsDialogKeyMap struct {
52	Confirm  key.Binding
53	Next     key.Binding
54	Previous key.Binding
55}
56
57func DefaultArgumentsDialogKeyMap() ArgumentsDialogKeyMap {
58	return ArgumentsDialogKeyMap{
59		Confirm: key.NewBinding(
60			key.WithKeys("enter"),
61			key.WithHelp("enter", "confirm"),
62		),
63
64		Next: key.NewBinding(
65			key.WithKeys("tab", "down"),
66			key.WithHelp("tab/↓", "next"),
67		),
68		Previous: key.NewBinding(
69			key.WithKeys("shift+tab", "up"),
70			key.WithHelp("shift+tab/↑", "previous"),
71		),
72	}
73}
74
75// FullHelp implements help.KeyMap.
76func (k ArgumentsDialogKeyMap) FullHelp() [][]key.Binding {
77	m := [][]key.Binding{}
78	slice := layout.KeyMapToSlice(k)
79	for i := 0; i < len(slice); i += 4 {
80		end := min(i+4, len(slice))
81		m = append(m, slice[i:end])
82	}
83	return m
84}
85
86// ShortHelp implements help.KeyMap.
87func (k ArgumentsDialogKeyMap) ShortHelp() []key.Binding {
88	return []key.Binding{
89		k.Confirm,
90		k.Next,
91		k.Previous,
92	}
93}