help.go RawHistoryFolder

1package styles
2
3import (
4	"github.com/charmbracelet/bubbles/help"
5	"github.com/charmbracelet/bubbles/key"
6	"github.com/charmbracelet/lipgloss"
7)
8
9// KeyMap defines keybindings that can be rendered as help.
10type KeyMap interface {
11	ShortHelp() []key.Binding
12	FullHelp() [][]key.Binding
13}
14
15// HistoryKeyMap defines keybindings for history browser.
16type HistoryKeyMap struct {
17	Up           key.Binding
18	Down         key.Binding
19	Tab1         key.Binding
20	Tab2         key.Binding
21	Tab3         key.Binding
22	Tab4         key.Binding
23	NextTab      key.Binding
24	PrevTab      key.Binding
25	Search       key.Binding
26	Open         key.Binding
27	Delete       key.Binding
28	DeleteDomain key.Binding
29	Cleanup      key.Binding
30	Filter       key.Binding
31	Help         key.Binding
32	Quit         key.Binding
33}
34
35// ShortHelp returns keybindings to show in compact help.
36func (k HistoryKeyMap) ShortHelp() []key.Binding {
37	return []key.Binding{k.Up, k.Down, k.Open, k.Search, k.Help, k.Quit}
38}
39
40// FullHelp returns keybindings for expanded help.
41func (k HistoryKeyMap) FullHelp() [][]key.Binding {
42	return [][]key.Binding{
43		{k.Up, k.Down, k.Open},
44		{k.NextTab, k.PrevTab, k.Tab1, k.Tab2, k.Tab3, k.Tab4},
45		{k.Search, k.Filter},
46		{k.Delete, k.DeleteDomain, k.Cleanup},
47		{k.Help, k.Quit},
48	}
49}
50
51// DefaultHistoryKeyMap returns the default history keybindings.
52func DefaultHistoryKeyMap() HistoryKeyMap {
53	return HistoryKeyMap{
54		Up: key.NewBinding(
55			key.WithKeys("up", "k"),
56			key.WithHelp("↑/k", "up"),
57		),
58		Down: key.NewBinding(
59			key.WithKeys("down", "j"),
60			key.WithHelp("↓/j", "down"),
61		),
62		Tab1: key.NewBinding(
63			key.WithKeys("1"),
64			key.WithHelp("1", "today"),
65		),
66		Tab2: key.NewBinding(
67			key.WithKeys("2"),
68			key.WithHelp("2", "yesterday"),
69		),
70		Tab3: key.NewBinding(
71			key.WithKeys("3"),
72			key.WithHelp("3", "this week"),
73		),
74		Tab4: key.NewBinding(
75			key.WithKeys("4"),
76			key.WithHelp("4", "older"),
77		),
78		NextTab: key.NewBinding(
79			key.WithKeys("tab"),
80			key.WithHelp("tab", "next tab"),
81		),
82		PrevTab: key.NewBinding(
83			key.WithKeys("shift+tab"),
84			key.WithHelp("S-tab", "prev tab"),
85		),
86		Search: key.NewBinding(
87			key.WithKeys("/"),
88			key.WithHelp("/", "search"),
89		),
90		Open: key.NewBinding(
91			key.WithKeys("enter"),
92			key.WithHelp("enter", "open"),
93		),
94		Delete: key.NewBinding(
95			key.WithKeys("d"),
96			key.WithHelp("d", "delete"),
97		),
98		DeleteDomain: key.NewBinding(
99			key.WithKeys("D"),
100			key.WithHelp("D", "delete domain"),
101		),
102		Cleanup: key.NewBinding(
103			key.WithKeys("c"),
104			key.WithHelp("c", "cleanup"),
105		),
106		Filter: key.NewBinding(
107			key.WithKeys("f"),
108			key.WithHelp("f", "filter domain"),
109		),
110		Help: key.NewBinding(
111			key.WithKeys("?"),
112			key.WithHelp("?", "help"),
113		),
114		Quit: key.NewBinding(
115			key.WithKeys("q", "ctrl+c"),
116			key.WithHelp("q", "quit"),
117		),
118	}
119}
120
121// NewStyledHelp creates a themed help model.
122func NewStyledHelp(theme *Theme) help.Model {
123	h := help.New()
124	h.Styles.ShortKey = lipgloss.NewStyle().Foreground(theme.Accent)
125	h.Styles.ShortDesc = lipgloss.NewStyle().Foreground(theme.Muted)
126	h.Styles.ShortSeparator = lipgloss.NewStyle().Foreground(theme.Border)
127	h.Styles.FullKey = lipgloss.NewStyle().Foreground(theme.Accent)
128	h.Styles.FullDesc = lipgloss.NewStyle().Foreground(theme.Text)
129	h.Styles.FullSeparator = lipgloss.NewStyle().Foreground(theme.Border)
130	return h
131}
132
133// DmenuKeyMap defines keybindings for dmenu browser.
134type DmenuKeyMap struct {
135	Up     key.Binding
136	Down   key.Binding
137	Open   key.Binding
138	Cancel key.Binding
139}
140
141// ShortHelp returns keybindings to show in compact help.
142func (k DmenuKeyMap) ShortHelp() []key.Binding {
143	return []key.Binding{k.Up, k.Down, k.Open, k.Cancel}
144}
145
146// FullHelp returns keybindings for expanded help.
147func (k DmenuKeyMap) FullHelp() [][]key.Binding {
148	return [][]key.Binding{
149		{k.Up, k.Down},
150		{k.Open, k.Cancel},
151	}
152}
153
154// DefaultDmenuKeyMap returns the default dmenu keybindings.
155func DefaultDmenuKeyMap() DmenuKeyMap {
156	return DmenuKeyMap{
157		Up: key.NewBinding(
158			key.WithKeys("up", "k"),
159			key.WithHelp("↑/k", "up"),
160		),
161		Down: key.NewBinding(
162			key.WithKeys("down", "j"),
163			key.WithHelp("↓/j", "down"),
164		),
165		Open: key.NewBinding(
166			key.WithKeys("enter"),
167			key.WithHelp("enter", "open"),
168		),
169		Cancel: key.NewBinding(
170			key.WithKeys("esc", "ctrl+c"),
171			key.WithHelp("esc", "cancel"),
172		),
173	}
174}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close