v0.4.0 2de4e1d

options.go RawHistoryFolder

1package ui
2
3import "github.com/bnema/nefergui/internal/css"
4
5// ContainerOption, ButtonOption and EditOption are separate option families.
6type ContainerOption interface{ container(*element) }
7type ButtonOption interface{ button(*element) }
8type EditOption interface{ edit(*element) }
9
10// ValueOption accepts CSS options and Disabled for pointer-backed controls.
11type ValueOption interface{ valueOption(*element) }
12
13// CommonOption is the concrete type of Key, ID, Class and Inline; it belongs
14// to every option family. It is exported only so the root facade can return it.
15type CommonOption struct{ apply func(*element) }
16
17func (o CommonOption) container(e *element)   { o.apply(e) }
18func (o CommonOption) button(e *element)      { o.apply(e) }
19func (o CommonOption) edit(e *element)        { o.apply(e) }
20func (o CommonOption) valueOption(e *element) { o.apply(e) }
21func Key(key string) CommonOption {
22	return CommonOption{func(e *element) { e.identity = &identity{key: key} }}
23}
24func ID(id string) CommonOption { return CommonOption{func(e *element) { e.id = id }} }
25func Class(class string) CommonOption {
26	return CommonOption{func(e *element) { e.classes = append(e.classes, class) }}
27}
28func Inline(src string) CommonOption {
29	return CommonOption{func(e *element) { e.inline, _ = css.ParseInline(src) }}
30}
31func applyContainer(e *element, opts []ContainerOption) {
32	for _, o := range opts {
33		o.container(e)
34	}
35}
36
37// DisabledOption is the concrete type of Disabled. It applies to every
38// interactive control (buttons, value controls and editors) but not to
39// containers or headings. Exported only so the root facade can return it.
40type DisabledOption struct{ disabled bool }
41
42func (o DisabledOption) button(e *element)      { e.disabled = o.disabled }
43func (o DisabledOption) edit(e *element)        { e.disabled = o.disabled }
44func (o DisabledOption) valueOption(e *element) { e.disabled = o.disabled }
45
46// Disabled blocks focus and interaction on an interactive control.
47func Disabled(v bool) DisabledOption { return DisabledOption{v} }
48
49// HeadingOption accepts common CSS options and Level, but not control options.
50type HeadingOption interface{ heading(*element) }
51
52func (o CommonOption) heading(e *element) { o.apply(e) }
53
54type headingLevel int
55
56func (level headingLevel) heading(e *element) { e.level = int(level) }
57
58// Level sets the accessibility heading level (1 through 6).
59func Level(level int) HeadingOption {
60	if level < 1 || level > 6 {
61		panic("nefergui: heading level must be between 1 and 6")
62	}
63	return headingLevel(level)
64}
65
66type editOnly struct{ placeholder string }
67
68func (o editOnly) edit(e *element)    { e.placeholder = o.placeholder }
69func Placeholder(v string) EditOption { return editOnly{v} }
70
71type passwordOption bool
72
73func (o passwordOption) edit(e *element) { e.password = bool(o) }
74func Password(v bool) EditOption         { return passwordOption(v) }

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 1

Tags 12

↑↓ moveenter openesc close