v0.5.1 657f658

styles_test.go RawHistoryFolder

1package render
2
3import (
4	"github.com/bnema/nefergui/internal/css"
5	"github.com/bnema/nefergui/internal/layout"
6	"testing"
7)
8
9func TestStyleInstances(t *testing.T) {
10	p, err := NewPreparer(128, 1)
11	if err != nil {
12		t.Fatal(err)
13	}
14	box := layout.Rect{X: 20, Y: 20, W: 80, H: 60}
15	sides := css.ColorSides{Top: css.Color{R: 1, A: 1}, Right: css.Color{G: 1, A: 1}, Bottom: css.Color{B: 1, A: 1}, Left: css.Color{R: 1, B: 1, A: 1}}
16	sh := css.Shadow{X: css.Length{Value: 2, Unit: "px"}, Y: css.Length{Value: 3, Unit: "px"}, Blur: css.Length{Value: 4, Unit: "px"}, Spread: css.Length{Value: 1, Unit: "px"}, Color: css.Color{A: .5}}
17	cmds := []layout.Command{
18		{Op: "rect", Rect: box, Radii: [4]float64{10, 10, 10, 10}, Color: css.Color{G: 1, A: 1}, Opacity: 1},
19		{Op: "border", Rect: box, Radii: [4]float64{10, 10, 10, 10}, Widths: layout.Edges{Top: 2, Right: 3, Bottom: 4, Left: 5}, Colors: sides, Color: css.Color{A: 1}, Opacity: 1},
20		{Op: "outline", Rect: box, Widths: layout.Edges{Top: 2, Right: 2, Bottom: 2, Left: 2}, Color: css.Color{B: 1, A: 1}, Opacity: 1},
21		{Op: "shadow", Rect: box, Shadow: &sh, Opacity: 1},
22		{Op: "preedit-caret", Rect: layout.Rect{X: 4, Y: 5, W: 1, H: 12}, Color: css.Color{R: 1, A: 1}, Opacity: 1},
23	}
24	frame, err := p.Prepare(cmds, 2, 300, 250)
25	if err != nil {
26		t.Fatal(err)
27	}
28	got, stats := ListInstances(frame)
29	if stats.Drawn != len(cmds) || len(stats.Skipped) != 0 {
30		t.Fatalf("stats=%+v", stats)
31	}
32	if got[0].Radii != [4]float32{20, 20, 20, 20} || got[0].Color != [4]float32{0, 1, 0, 1} {
33		t.Fatalf("fill=%+v", got[0])
34	}
35	if got[1].KindLayer[0] != 2 || got[1].Widths != [4]float32{4, 6, 8, 10} || got[1].Sides[0] != [4]float32{1, 0, 0, 1} || got[1].Sides[1] != [4]float32{0, 1, 0, 1} || got[1].Sides[2] != [4]float32{0, 0, 1, 1} || got[1].Sides[3] != [4]float32{1, 0, 1, 1} {
36		t.Fatalf("border=%+v", got[1])
37	}
38	if got[2].KindLayer[0] != 3 || got[2].Bounds != [4]float32{36, 36, 168, 128} || got[2].Shape != [4]float32{40, 40, 160, 120} || got[2].Color != [4]float32{0, 0, 1, 1} {
39		t.Fatalf("outline=%+v", got[2])
40	}
41	if got[3].KindLayer[0] != 4 || got[3].Bounds != [4]float32{30, 32, 188, 148} || got[3].Shadow != [4]float32{4, 6, 8, 2} || got[3].Color != [4]float32{0, 0, 0, .5} {
42		t.Fatalf("shadow=%+v", got[3])
43	}
44	if got[4].KindLayer[0] != 0 || got[4].Bounds != [4]float32{8, 10, 2, 24} || got[4].Color != [4]float32{1, 0, 0, 1} {
45		t.Fatalf("caret=%+v", got[4])
46	}
47	sh.Inset = true
48	frame, err = p.Prepare([]layout.Command{{Op: "shadow", Rect: box, Shadow: &sh, Opacity: 1}}, 2, 300, 250)
49	if err != nil {
50		t.Fatal(err)
51	}
52	got, stats = ListInstances(frame)
53	if len(stats.Skipped) != 0 || len(got) != 1 || got[0].KindLayer[0] != 5 || got[0].Bounds != [4]float32{40, 40, 160, 120} {
54		t.Fatalf("inset=%+v %+v", got, stats)
55	}
56	if _, err = p.Prepare([]layout.Command{{Op: "shadow", Rect: box}}, 1, 300, 250); err == nil {
57		t.Fatal("accepted missing shadow")
58	}
59}

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