v0.2.60 3cd4df6

input_test.go RawHistoryFolder

1package tui
2
3import "testing"
4
5func TestReaderParsesCSIUShiftEnter(t *testing.T) {
6	k := readKey(t, "\x1b[13;2u")
7	if k.Kind != KeyEnter || !k.Shift || k.Alt {
8		t.Fatalf("Read kind=%v shift=%v alt=%v, want shift+enter", k.Kind, k.Shift, k.Alt)
9	}
10}
11
12func TestReaderParsesModifyOtherKeysShiftEnter(t *testing.T) {
13	k := readKey(t, "\x1b[27;2;13~")
14	if k.Kind != KeyEnter || !k.Shift || k.Alt {
15		t.Fatalf("Read kind=%v shift=%v alt=%v, want shift+enter", k.Kind, k.Shift, k.Alt)
16	}
17}
18
19func TestReaderParsesCSIUCtrlC(t *testing.T) {
20	k := readKey(t, "\x1b[99;5u")
21	if k.Kind != KeyCtrlC || !k.Ctrl {
22		t.Fatalf("Read kind=%v ctrl=%v, want ctrl+c", k.Kind, k.Ctrl)
23	}
24}
25
26func TestReaderParsesCSIUCtrlNumber(t *testing.T) {
27	k := readKey(t, "\x1b[49;5u")
28	if k.Kind != KeyRune || k.Rune != '1' || !k.Ctrl {
29		t.Fatalf("Read kind=%v rune=%q ctrl=%v, want ctrl+1", k.Kind, k.Rune, k.Ctrl)
30	}
31}
32
33func TestReaderParsesCSIUSuperNumber(t *testing.T) {
34	k := readKey(t, "\x1b[50;9u")
35	if k.Kind != KeyRune || k.Rune != '2' || !k.Super {
36		t.Fatalf("Read kind=%v rune=%q super=%v, want super+2", k.Kind, k.Rune, k.Super)
37	}
38}
39
40func TestReaderParsesCSIUSuperNumberWithEventType(t *testing.T) {
41	k := readKey(t, "\x1b[51;9:3u")
42	if k.Kind != KeyRune || k.Rune != '3' || !k.Super {
43		t.Fatalf("Read kind=%v rune=%q super=%v, want super+3", k.Kind, k.Rune, k.Super)
44	}
45}
46
47func TestReaderParsesCSIUHyperNumberAsSuper(t *testing.T) {
48	k := readKey(t, "\x1b[52;33u")
49	if k.Kind != KeyRune || k.Rune != '4' || !k.Super {
50		t.Fatalf("Read kind=%v rune=%q super=%v, want hyper+4 as super", k.Kind, k.Rune, k.Super)
51	}
52}
53
54func TestReaderParsesRawCtrlVAsClipboardPaste(t *testing.T) {
55	k := readKey(t, "\x16")
56	if k.Kind != KeyPasteClipboard || !k.Ctrl {
57		t.Fatalf("Read kind=%v ctrl=%v, want ctrl+v clipboard paste", k.Kind, k.Ctrl)
58	}
59}
60
61func TestReaderParsesCSIUCtrlVAsClipboardPaste(t *testing.T) {
62	k := readKey(t, "\x1b[118;5u")
63	if k.Kind != KeyPasteClipboard || !k.Ctrl {
64		t.Fatalf("Read kind=%v ctrl=%v, want enhanced ctrl+v clipboard paste", k.Kind, k.Ctrl)
65	}
66}
67
68func TestReaderParsesModifyOtherKeysCtrlC(t *testing.T) {
69	k := readKey(t, "\x1b[27;5;99~")
70	if k.Kind != KeyCtrlC || !k.Ctrl {
71		t.Fatalf("Read kind=%v ctrl=%v, want ctrl+c", k.Kind, k.Ctrl)
72	}
73}
74
75func TestReaderParsesCSIUEsc(t *testing.T) {
76	k := readKey(t, "\x1b[27u")
77	if k.Kind != KeyEsc {
78		t.Fatalf("Read kind=%v, want esc", k.Kind)
79	}
80}
81
82func TestReaderParsesCSIUTabAndBackspace(t *testing.T) {
83	if k := readKey(t, "\x1b[9u"); k.Kind != KeyTab {
84		t.Fatalf("Read kind=%v, want tab", k.Kind)
85	}
86	if k := readKey(t, "\x1b[9;2u"); k.Kind != KeyShiftTab {
87		t.Fatalf("Read kind=%v, want shift-tab", k.Kind)
88	}
89	if k := readKey(t, "\x1b[127u"); k.Kind != KeyBackspace {
90		t.Fatalf("Read kind=%v, want backspace", k.Kind)
91	}
92}
93
94func TestReaderParsesSGRMouseWheel(t *testing.T) {
95	cases := []struct {
96		seq  string
97		want KeyKind
98	}{
99		{"\x1b[<64;10;20M", KeyMouseWheelUp},
100		{"\x1b[<65;10;20M", KeyMouseWheelDown},
101	}
102	for _, tc := range cases {
103		k := readKey(t, tc.seq)
104		if k.Kind != tc.want {
105			t.Fatalf("Read(%q) kind=%v, want %v", tc.seq, k.Kind, tc.want)
106		}
107	}
108}
109
110func readKey(t *testing.T, seq string) Key {
111	t.Helper()
112	idx := 0
113	r := NewReader(func() (byte, error) {
114		b := seq[idx]
115		idx++
116		return b, nil
117	})
118	k, err := r.Read()
119	if err != nil {
120		t.Fatalf("Read(%q): %v", seq, err)
121	}
122	return k
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 1

Tags 476

↑↓ moveenter openesc close