1package quit
2
3import (
4 "github.com/charmbracelet/bubbles/v2/key"
5 "github.com/opencode-ai/opencode/internal/tui/layout"
6)
7
8// KeyMap defines the keyboard bindings for the quit dialog.
9type KeyMap struct {
10 LeftRight key.Binding
11 EnterSpace key.Binding
12 Yes key.Binding
13 No key.Binding
14 Tab key.Binding
15}
16
17func DefaultKeymap() KeyMap {
18 return KeyMap{
19 LeftRight: key.NewBinding(
20 key.WithKeys("left", "right"),
21 key.WithHelp("←/→", "switch options"),
22 ),
23 EnterSpace: key.NewBinding(
24 key.WithKeys("enter", " "),
25 key.WithHelp("enter/space", "confirm"),
26 ),
27 Yes: key.NewBinding(
28 key.WithKeys("y", "Y", "ctrl+c"),
29 key.WithHelp("y/Y/ctrl+c", "yes"),
30 ),
31 No: key.NewBinding(
32 key.WithKeys("n", "N"),
33 key.WithHelp("n/N", "no"),
34 ),
35 Tab: key.NewBinding(
36 key.WithKeys("tab"),
37 key.WithHelp("tab", "switch options"),
38 ),
39 }
40}
41
42// FullHelp implements help.KeyMap.
43func (k KeyMap) FullHelp() [][]key.Binding {
44 m := [][]key.Binding{}
45 slice := layout.KeyMapToSlice(k)
46 for i := 0; i < len(slice); i += 4 {
47 end := min(i+4, len(slice))
48 m = append(m, slice[i:end])
49 }
50 return m
51}
52
53// ShortHelp implements help.KeyMap.
54func (k KeyMap) ShortHelp() []key.Binding {
55 return []key.Binding{
56 k.LeftRight,
57 k.EnterSpace,
58 }
59}