keys.go

 1package list
 2
 3import (
 4	"github.com/charmbracelet/bubbles/v2/key"
 5)
 6
 7type KeyMap struct {
 8	Down,
 9	Up,
10	DownOneItem,
11	UpOneItem,
12	HalfPageDown,
13	HalfPageUp,
14	Home,
15	End key.Binding
16}
17
18func DefaultKeyMap() KeyMap {
19	return KeyMap{
20		Down: key.NewBinding(
21			key.WithKeys("down", "ctrl+j", "ctrl+n", "j"),
22			key.WithHelp("↓", "down"),
23		),
24		Up: key.NewBinding(
25			key.WithKeys("up", "ctrl+k", "ctrl+p", "k"),
26			key.WithHelp("↑", "up"),
27		),
28		UpOneItem: key.NewBinding(
29			key.WithKeys("shift+up", "K"),
30			key.WithHelp("shift+↑", "up one item"),
31		),
32		DownOneItem: key.NewBinding(
33			key.WithKeys("shift+down", "J"),
34			key.WithHelp("shift+↓", "down one item"),
35		),
36		HalfPageDown: key.NewBinding(
37			key.WithKeys("d"),
38			key.WithHelp("d", "half page down"),
39		),
40		HalfPageUp: key.NewBinding(
41			key.WithKeys("u"),
42			key.WithHelp("u", "half page up"),
43		),
44		Home: key.NewBinding(
45			key.WithKeys("g", "home"),
46			key.WithHelp("g", "home"),
47		),
48		End: key.NewBinding(
49			key.WithKeys("G", "end"),
50			key.WithHelp("G", "end"),
51		),
52	}
53}
54
55// KeyBindings implements layout.KeyMapProvider
56func (k KeyMap) KeyBindings() []key.Binding {
57	return []key.Binding{
58		k.Down,
59		k.Up,
60		k.DownOneItem,
61		k.UpOneItem,
62		k.HalfPageDown,
63		k.HalfPageUp,
64		k.Home,
65		k.End,
66	}
67}