keys.go

 1package chat
 2
 3import (
 4	"charm.land/bubbles/v2/key"
 5)
 6
 7type KeyMap struct {
 8	NewSession    key.Binding
 9	AddAttachment key.Binding
10	Cancel        key.Binding
11	Tab           key.Binding
12	Details       key.Binding
13}
14
15type PillsKeyMap struct {
16	Left  key.Binding
17	Right key.Binding
18	Up    key.Binding
19	Down  key.Binding
20}
21
22func DefaultKeyMap() KeyMap {
23	return KeyMap{
24		NewSession: key.NewBinding(
25			key.WithKeys("ctrl+n"),
26			key.WithHelp("ctrl+n", "new session"),
27		),
28		AddAttachment: key.NewBinding(
29			key.WithKeys("ctrl+f"),
30			key.WithHelp("ctrl+f", "add attachment"),
31		),
32		Cancel: key.NewBinding(
33			key.WithKeys("esc", "alt+esc"),
34			key.WithHelp("esc", "cancel"),
35		),
36		Tab: key.NewBinding(
37			key.WithKeys("tab"),
38			key.WithHelp("tab", "change focus"),
39		),
40		Details: key.NewBinding(
41			key.WithKeys("ctrl+d"),
42			key.WithHelp("ctrl+d", "toggle details"),
43		),
44	}
45}
46
47func DefaultPillsKeyMap() PillsKeyMap {
48	return PillsKeyMap{
49		Left: key.NewBinding(
50			key.WithKeys("left"),
51			key.WithHelp("←/→", "section"),
52		),
53		Right: key.NewBinding(
54			key.WithKeys("right"),
55			key.WithHelp("←/→", "section"),
56		),
57		Up: key.NewBinding(
58			key.WithKeys("up", "k"),
59			key.WithHelp("↑/k", "focus chat"),
60		),
61		Down: key.NewBinding(
62			key.WithKeys("down", "j"),
63			key.WithHelp("↓/j", "focus pills"),
64		),
65	}
66}