v0.5.0 5fd5066

example_test.go RawHistoryFolder

1package nefergui_test
2
3import (
4	"fmt"
5	"log"
6
7	"github.com/bnema/nefergui"
8)
9
10// ExampleRenderer shows the shape of a client loop. The Wayland side (display
11// connection, linux-dmabuf feedback, buffer import, event dispatch) belongs to
12// the application, for instance through github.com/bnema/neferclient; it is
13// elided here. The example needs a GPU and a compositor, so it is compiled but
14// not run by go test.
15func ExampleRenderer() {
16	type model struct{ count int }
17	view := func(f *nefergui.Frame, m *model) {
18		root := f.Root().Column()
19		root.Text("Hello, Wayland!")
20		if root.Button("Count", nefergui.Key("count")).Activated() {
21			m.count++
22		}
23		root.Text(fmt.Sprintf("Clicked %d times", m.count))
24	}
25
26	// mainDevice and formats come from the compositor's linux-dmabuf feedback.
27	var (
28		mainDevice uint64
29		formats    []nefergui.Format
30	)
31	r, err := nefergui.NewRenderer(nefergui.RendererConfig{MainDevice: mainDevice, Formats: formats})
32	if err != nil {
33		log.Fatal(err)
34	}
35	defer r.Close()
36
37	// Forward the surface size, then wire events as they arrive.
38	r.Resize(320, 200, 1)
39	r.Input(&nefergui.Input{Kind: nefergui.InputPointerMotion, X: 10, Y: 10})
40
41	m := &model{}
42	var out nefergui.Output
43	// One iteration of the client loop; real clients repeat it forever.
44	drawn, err := r.Render(&out, m, view)
45	if err != nil {
46		log.Fatal(err)
47	}
48	if drawn {
49		// Import out.Planes as a wl_buffer when out.NewBuffer is set, attach
50		// it with the Acquire/Release points, commit, and call r.Released
51		// when out.ReleaseFD becomes readable.
52		_ = out.Buffer
53	}
54	// Then sleep until a Wayland event, <-r.Wake(), or a short timer when
55	// r.Pending() reports a frame waiting for the GPU.
56}

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