detached f2d166b

layout_bench_test.go RawHistoryFolder

1package core
2
3import (
4	"context"
5	"fmt"
6	"testing"
7
8	"github.com/bnema/neferwl/internal/ports"
9)
10
11func benchLane(n int, stamped bool) *Workspace {
12	w := spanWorkspace(OverflowScroll, n)
13	if stamped {
14		stampSpans(w, 0, n-1)
15	}
16	w.Focus = n / 2
17	return w
18}
19
20func benchLanes(b *testing.B, f func(b *testing.B, w *Workspace)) {
21	for _, n := range []int{16, 64} {
22		for _, stamped := range []bool{false, true} {
23			b.Run(fmt.Sprintf("cols=%d/stamped=%t", n, stamped), func(b *testing.B) {
24				w := benchLane(n, stamped)
25				b.ReportAllocs()
26				f(b, w)
27			})
28		}
29	}
30}
31
32func BenchmarkSnapPoints(b *testing.B) {
33	benchLanes(b, func(b *testing.B, w *Workspace) {
34		for b.Loop() {
35			_ = w.snapPoints()
36		}
37	})
38}
39
40func BenchmarkLayout(b *testing.B) {
41	benchLanes(b, func(b *testing.B, w *Workspace) {
42		for b.Loop() {
43			_ = w.Layout()
44		}
45	})
46}
47
48func BenchmarkColumnRects(b *testing.B) {
49	benchLanes(b, func(b *testing.B, w *Workspace) {
50		var buf []Rect
51		for b.Loop() {
52			buf = w.columnRectsInto(buf, false)
53		}
54	})
55}
56
57func BenchmarkScroll(b *testing.B) {
58	benchLanes(b, func(b *testing.B, w *Workspace) {
59		for b.Loop() {
60			w.scroll()
61		}
62	})
63}
64
65// BenchmarkBorderMotion is one pointer motion of a border resize with a
66// publish; "same" repeats a position, so nothing changes after the first.
67func BenchmarkBorderMotion(b *testing.B) {
68	for _, mode := range []string{"moving", "same"} {
69		b.Run(mode, func(b *testing.B) {
70			var cfg ports.Config
71			cfg.Keyboard.CmdKey = "super"
72			cfg.Layout.MaxColumns = 3
73			scenes, cmds := make(chan []ports.Scene, 1), make(chan ports.ClientCommand, 1024)
74			c, err := New(cfg, Channels{Scenes: scenes, Commands: cmds}, Options{})
75			if err != nil {
76				b.Fatal(err)
77			}
78			c.addScreen(ports.OutputInfo{Name: "A", Width: 1920, Height: 1080})
79			sc := c.cur()
80			w := sc.mon.Current()
81			w.Overflow = OverflowScroll
82			for id := WindowID(1); id <= 12; id++ {
83				w.AddWindow(id)
84			}
85			sc.arrange()
86			ctx := context.Background()
87			if err := c.publish(ctx); err != nil {
88				b.Fatal(err)
89			}
90			rs := w.columnRects()
91			g := newBorderResize(c, sc, w, border{kind: borderColumn, col: 0}, btnRight)
92			x := float64(rs[0].X + rs[0].W)
93			c.cursorY = 100
94			n := 0
95			b.ReportAllocs()
96			for b.Loop() {
97				c.cursorX = x
98				if mode == "moving" {
99					c.cursorX += float64(n%2*8) + 8
100					n++
101				}
102				for len(scenes) > 0 {
103					<-scenes
104				}
105				for len(cmds) > 0 {
106					<-cmds
107				}
108				if err := g.motion(ctx, 0); err != nil {
109					b.Fatal(err)
110				}
111			}
112		})
113	}
114}

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