v0.4.0 76bcd84

view.go RawHistoryFolder

1package selection
2
3import (
4	"github.com/bnema/nefergui"
5
6	"github.com/bnema/nefercap/internal/ports"
7)
8
9// view draws the scene. Geometry goes through Node.Rect, so no CSS strings
10// are built per frame; classes come from the embedded stylesheet. Boxes with no
11// area are not emitted at all, so an idle surface is one dim box plus the
12// header and footer, and no empty chip is painted.
13func view(f *nefergui.Frame, m *model) {
14	m.syncMode() // a Tab on another overlay redraws this one
15	m.refreshFooter()
16	root := f.Root(nefergui.Class("root"))
17	st := root.Stack(nefergui.Class("scene"))
18	if drawsBackdrop(m) {
19		// The frozen screen, scaled to fill the logical surface.
20		box := st.Box(nefergui.Key("backdrop"), nefergui.Class("backdrop")).Rect(0, 0, float64(m.w), float64(m.h))
21		box.Image(m.backdrop)
22	}
23	s := m.scene()
24	for i, r := range s.dim {
25		box(st, dimKeys[i], "dim", r)
26	}
27	for i, r := range s.grid {
28		box(st, gridKeys[i], "grid", r)
29	}
30	for i, r := range s.edges {
31		box(st, edgeKeys[i], "edge", r)
32	}
33	if n := tag(st, "label", s.label); n.ok {
34		n.node.Text(m.label.text)
35	}
36	if n := tag(st, "badge", s.badge); n.ok {
37		n.node.Text(badgeText(m.mode))
38	}
39	if n := tag(st, "header", s.header); n.ok {
40		n.node.Text(m.header)
41	}
42	if n := tag(st, "footer", s.footer); n.ok {
43		n.node.Text(m.footerText)
44	}
45}
46
47// drawsBackdrop: a screenshot selection shows the frozen screen; a recording
48// selects on the live screen.
49func drawsBackdrop(m *model) bool {
50	return m.backdrop != nil && m.mode == ports.Screenshot && m.w > 0 && m.h > 0
51}
52
53type tagged struct {
54	node nefergui.Node
55	ok   bool
56}
57
58func box(st nefergui.Node, key, class string, r frect) {
59	if r.w > 0 && r.h > 0 {
60		st.Box(nefergui.Key(key), nefergui.Class(class)).Rect(r.x, r.y, r.w, r.h)
61	}
62}
63
64func tag(st nefergui.Node, key string, r frect) tagged {
65	if r.w <= 0 || r.h <= 0 {
66		return tagged{}
67	}
68	return tagged{st.Box(nefergui.Key(key), nefergui.Class("tag")).Rect(r.x, r.y, r.w, r.h), true}
69}
70
71// Static keys avoid building identity strings per frame.
72var (
73	dimKeys  = [4]string{"dim0", "dim1", "dim2", "dim3"}
74	gridKeys = [6]string{"grid0", "grid1", "grid2", "grid3", "grid4", "grid5"}
75	edgeKeys = [4]string{"edge0", "edge1", "edge2", "edge3"}
76)

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 2

Tags 9

↑↓ moveenter openesc close