v0.5.1 657f658

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.
15// It is plain data rather than a closure, so creating one never allocates.
16type CommonOption struct {
17	kind commonKind
18	s    string
19}
20
21type commonKind uint8
22
23const (
24	optKey commonKind = iota
25	optID
26	optClass
27	optInline
28)
29
30func (o CommonOption) apply(e *element) {
31	switch o.kind {
32	case optKey:
33		e.key, e.hasKey = o.s, true
34	case optID:
35		e.id = o.s
36	case optClass:
37		e.classes = append(e.classes, o.s)
38	case optInline:
39		e.inline, _ = css.ParseInline(o.s)
40	}
41}
42func (o CommonOption) container(e *element)   { o.apply(e) }
43func (o CommonOption) button(e *element)      { o.apply(e) }
44func (o CommonOption) edit(e *element)        { o.apply(e) }
45func (o CommonOption) valueOption(e *element) { o.apply(e) }
46func Key(key string) CommonOption             { return CommonOption{optKey, key} }
47func ID(id string) CommonOption               { return CommonOption{optID, id} }
48func Class(class string) CommonOption         { return CommonOption{optClass, class} }
49func Inline(src string) CommonOption          { return CommonOption{optInline, src} }
50func applyContainer(e *element, opts []ContainerOption) {
51	for _, o := range opts {
52		o.container(e)
53	}
54}
55
56// DisabledOption is the concrete type of Disabled. It applies to every
57// interactive control (buttons, value controls and editors) but not to
58// containers or headings. Exported only so the root facade can return it.
59type DisabledOption struct{ disabled bool }
60
61func (o DisabledOption) button(e *element)      { e.disabled = o.disabled }
62func (o DisabledOption) edit(e *element)        { e.disabled = o.disabled }
63func (o DisabledOption) valueOption(e *element) { e.disabled = o.disabled }
64
65// Disabled blocks focus and interaction on an interactive control.
66func Disabled(v bool) DisabledOption { return DisabledOption{v} }
67
68// HeadingOption accepts common CSS options and Level, but not control options.
69type HeadingOption interface{ heading(*element) }
70
71func (o CommonOption) heading(e *element) { o.apply(e) }
72
73type headingLevel int
74
75func (level headingLevel) heading(e *element) { e.level = int(level) }
76
77// Level sets the accessibility heading level (1 through 6).
78func Level(level int) HeadingOption {
79	if level < 1 || level > 6 {
80		panic("nefergui: heading level must be between 1 and 6")
81	}
82	return headingLevel(level)
83}
84
85type editOnly struct{ placeholder string }
86
87func (o editOnly) edit(e *element)    { e.placeholder = o.placeholder }
88func Placeholder(v string) EditOption { return editOnly{v} }
89
90type passwordOption bool
91
92func (o passwordOption) edit(e *element) { e.password = bool(o) }
93func 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