v0.1.0 47aaa0f

example_test.go RawHistoryFolder

1package nefergui_test
2
3import (
4	"context"
5	"fmt"
6	"log"
7
8	"github.com/bnema/nefergui"
9)
10
11// The README counter. Run needs a Wayland session, so this example is
12// compiled but not executed by go test.
13func Example_counter() {
14	count := 0
15	view := func(f *nefergui.Frame, count *int) {
16		root := f.Root().Column()
17		root.Text("Hello, Wayland!")
18		if root.Button("Count", nefergui.Key("count")).Activated() {
19			*count++
20		}
21		root.Text(fmt.Sprintf("Clicked %d times", *count))
22	}
23	if err := nefergui.Run(context.Background(), &count, view,
24		nefergui.Title("Hello"), nefergui.Size(320, 200)); err != nil {
25		log.Fatal(err)
26	}
27}
28
29// The product-design example. Run needs a Wayland session, so this example is
30// compiled but not executed by go test; examples/demo runs it.
31func Example_compileOnly() {
32	type Model struct {
33		Page, Name, Status string
34		DarkMode           bool
35	}
36	model := Model{Page: "home", Status: "Prêt"}
37	navButton := func(parent nefergui.Node, m *Model, label, page string) {
38		opts := []nefergui.ButtonOption{nefergui.Key(page), nefergui.Class("menu-item")}
39		if m.Page == page {
40			opts = append(opts, nefergui.Class("active"))
41		}
42		if parent.Button(label, opts...).Activated() {
43			m.Page = page
44		}
45	}
46	home := func(parent nefergui.Node, m *Model) {
47		section := parent.Section(nefergui.Class("welcome"))
48		section.Heading("Bienvenue", nefergui.Level(2))
49		section.Text("Une interface native écrite entièrement en Go.")
50		section.Input("Votre nom", &m.Name, nefergui.Key("name"), nefergui.Placeholder("Ada"))
51		actions := section.Row(nefergui.Class("actions"))
52		if actions.Button("Continuer", nefergui.Key("continue"), nefergui.Class("primary"), nefergui.Disabled(m.Name == "")).Activated() {
53			m.Status = "Bonjour " + m.Name
54		}
55	}
56	app := func(f *nefergui.Frame, m *Model) {
57		root := f.Root(nefergui.Class("app"))
58		header := root.Header(nefergui.Class("header"))
59		header.Heading("Demo", nefergui.Level(1), nefergui.Class("logo"))
60		menu := header.Nav(nefergui.Class("menu"))
61		navButton(menu, m, "Accueil", "home")
62		navButton(menu, m, "Paramètres", "settings")
63		header.Checkbox("Thème sombre", &m.DarkMode, nefergui.Key("dark-mode"))
64		content := root.Main(nefergui.Class("content"))
65		switch m.Page {
66		case "home":
67			home(content, m)
68		case "settings":
69			home(content, m)
70		}
71		root.Footer(nefergui.Class("status-bar")).Text(m.Status)
72	}
73	_ = nefergui.Run(context.Background(), &model, app, nefergui.Title("Demo"), nefergui.Size(960, 640), nefergui.Styles("app.css"))
74}

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