scene_animating_test.go RawHistoryFolder

1package core
2
3import (
4	"context"
5	"testing"
6	"time"
7
8	"github.com/bnema/neferwl/internal/ports"
9)
10
11// A scene published while a spring runs carries Animating, so its flip wakes
12// core for the next frame; the scene the spring settles on does not, and
13// neither does any scene of an idle output.
14func TestSceneAnimatingFollowsSprings(t *testing.T) {
15	c, ic := indicatorCore(t)
16	c.cfg.Animations.On = true
17	a := c.cur()
18	a.mon.AddWindow(1)
19	a.mon.AddWindow(2)
20	if s := indicatorScene(t, c); s.Animating {
21		t.Fatal("an idle output publishes an animating scene")
22	}
23
24	// A slide starts.
25	w := a.mon.Current()
26	w.view.off = 100
27	w.view.motion = newMotion(viewSpring(w.view.off, 0), ic.now, 1)
28	ic.now = ic.now.Add(10 * time.Millisecond)
29	first := stepScenes(t, c, a)["A"]
30	if !first.Animating {
31		t.Fatal("a scene with a running spring is not animating")
32	}
33	ic.now = ic.now.Add(10 * time.Millisecond)
34	if second := stepScenes(t, c, a)["A"]; !second.Animating || second.Seq == first.Seq {
35		t.Fatalf("running slide: animating=%v Seq %d (was %d)", second.Animating, second.Seq, first.Seq)
36	}
37
38	// The step that lands the spring publishes the last scene: nothing more
39	// is due, so it must not wake core again.
40	ic.now = ic.now.Add(10 * time.Second)
41	last := stepScenes(t, c, a)["A"]
42	if last.Animating {
43		t.Fatal("the scene a spring settles on is animating")
44	}
45	if a.springing() {
46		t.Fatal("bad setup: the spring still runs")
47	}
48	// Idle again: still false, and the Seq is held (no extra recomposition).
49	if err := c.publish(context.Background()); err != nil {
50		t.Fatal(err)
51	}
52	idle := (<-c.ch.Scenes)[0]
53	if idle.Animating || idle.Seq != last.Seq || !idle.SameAs(last) {
54		t.Fatalf("idle publish: animating=%v Seq %d (was %d)", idle.Animating, idle.Seq, last.Seq)
55	}
56}
57
58// Animating is per output: a spring on one does not mark the other.
59func TestSceneAnimatingIsPerOutput(t *testing.T) {
60	c, ic := indicatorCore(t)
61	c.cfg.Animations.On = true
62	a := c.cur()
63	c.addScreen(ports.OutputInfo{Name: "B", Width: 300, Height: 200})
64	b := c.screens[1]
65	a.mon.AddWindow(1)
66	b.mon.AddWindow(2)
67	indicatorScene(t, c)
68	w := b.mon.Current()
69	w.view.off = 100
70	w.view.motion = newMotion(viewSpring(w.view.off, 0), ic.now, 1)
71	ic.now = ic.now.Add(10 * time.Millisecond)
72	got := stepScenes(t, c, b)
73	if !got["B"].Animating || got["A"].Animating {
74		t.Fatalf("animating A=%v B=%v, want B only", got["A"].Animating, got["B"].Animating)
75	}
76}
77
78// A spring that settles on the very scene its last running step drew (the
79// tail rounds to the final pixel) must still publish a scene with Animating
80// off, with a fresh Seq: SameAs ignores the flag, and the outputs would
81// otherwise keep the animating scene they show and wake core on every later
82// flip.
83func TestSettledSceneSameAsPreviousClearsAnimating(t *testing.T) {
84	// Commands (rehit) are not read: room for every step.
85	c, ic := indicatorCoreWith(t, make(chan ports.ClientCommand, 4096))
86	c.cfg.Animations.On = true
87	a := c.cur()
88	a.mon.AddWindow(1)
89	a.mon.AddWindow(2)
90	indicatorScene(t, c)
91
92	w := a.mon.Current()
93	w.view.off = 100
94	w.view.motion = newMotion(viewSpring(w.view.off, 0), ic.now, 1)
95	// Step in 1 ms until the spring settles: the snap settles it once it is
96	// within half a pixel of its target, where the last running scene can
97	// draw the same pixels as the settled one.
98	start := ic.now
99	var running, settled ports.Scene
100	for ms := 1; ; ms++ {
101		if ms > 2000 {
102			t.Fatal("the spring never settles")
103		}
104		ic.now = start.Add(time.Duration(ms) * time.Millisecond)
105		settled = stepScenes(t, c, a)["A"]
106		if !a.springing() {
107			break
108		}
109		running = settled
110	}
111	if !running.Animating {
112		t.Fatalf("bad setup: last running scene animating=%v", running.Animating)
113	}
114	if !settled.SameAs(running) {
115		t.Fatal("bad setup: the settled scene differs from the last running one")
116	}
117	if settled.Animating {
118		t.Fatal("the settled scene is animating")
119	}
120	if settled.Seq == running.Seq {
121		t.Fatalf("settled scene kept the animating scene's Seq %d", running.Seq)
122	}
123}

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 23

Tags 10

↑↓ moveenter openesc close