main 3d41bc5

control_test.go RawHistoryFolder

1package app
2
3import (
4	"bytes"
5	"context"
6	"os"
7	"path/filepath"
8	"testing"
9	"time"
10
11	"github.com/bnema/nefercap/internal/adapters/cli"
12	"github.com/bnema/nefercap/internal/adapters/control"
13)
14
15func TestControlCommands(t *testing.T) {
16	runtime := filepath.Join(t.TempDir(), "runtime")
17	if err := os.Mkdir(runtime, 0o700); err != nil {
18		t.Fatal(err)
19	}
20	t.Setenv("XDG_RUNTIME_DIR", runtime)
21	var out bytes.Buffer
22	ctx := context.Background()
23	if handled, err := controlCommand(ctx, cli.Status, &out); !handled || err != nil || out.String() != "idle\n" {
24		t.Fatalf("idle: %t %v %s", handled, err, out.String())
25	}
26	if handled, err := controlCommand(ctx, cli.Rec, &out); handled || err != nil {
27		t.Fatalf("idle rec: %t %v", handled, err)
28	}
29	server, err := control.Listen()
30	if err != nil {
31		t.Fatal(err)
32	}
33	defer server.Close()
34	out.Reset()
35	if handled, err := controlCommand(ctx, cli.Status, &out); !handled || err != nil || out.String() != "recording\n" {
36		t.Fatalf("active: %t %v %s", handled, err, out.String())
37	}
38	if handled, err := controlCommand(ctx, cli.Rec, &out); !handled || err != nil {
39		t.Fatalf("toggle: %t %v", handled, err)
40	}
41	select {
42	case got := <-server.Requests():
43		if got != control.RequestStop {
44			t.Fatalf("request: %v", got)
45		}
46	case <-time.After(time.Second):
47		t.Fatal("stop not delivered")
48	}
49}
50
51func TestAllInOneStopsActiveRecording(t *testing.T) {
52	runtime := filepath.Join(t.TempDir(), "runtime")
53	if err := os.Mkdir(runtime, 0o700); err != nil {
54		t.Fatal(err)
55	}
56	t.Setenv("XDG_RUNTIME_DIR", runtime)
57	var out bytes.Buffer
58	ctx := context.Background()
59	if handled, err := controlCommand(ctx, cli.AllInOne, &out); handled || err != nil {
60		t.Fatalf("idle all-in-one must open the selector: %t %v", handled, err)
61	}
62	server, err := control.Listen()
63	if err != nil {
64		t.Fatal(err)
65	}
66	defer server.Close()
67	if handled, err := controlCommand(ctx, cli.AllInOne, &out); !handled || err != nil || out.Len() != 0 {
68		t.Fatalf("active all-in-one: %t %v %q", handled, err, out.String())
69	}
70	select {
71	case got := <-server.Requests():
72		if got != control.RequestStop {
73			t.Fatalf("request: %v", got)
74		}
75	case <-time.After(time.Second):
76		t.Fatal("stop not delivered")
77	}
78}
79
80func TestStopOnRequest(t *testing.T) {
81	ctx, cancel := context.WithCancel(context.Background())
82	defer cancel()
83	requests := make(chan control.Request, 1)
84	done := stopOnRequest(ctx, requests, cancel)
85	requests <- control.RequestStop
86	select {
87	case <-done:
88	case <-time.After(time.Second):
89		t.Fatal("control waiter did not stop")
90	}
91	if ctx.Err() != context.Canceled {
92		t.Fatal("stop did not cancel recording")
93	}
94}

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 2

Tags 9

↑↓ moveenter openesc close