textinput_test.go RawHistoryFolder

1package ui
2
3import (
4	"testing"
5
6	renderer "github.com/bnema/vev-vt"
7	"github.com/bnema/vev/internal/domain"
8	"github.com/stretchr/testify/require"
9)
10
11func TestTextInputEditsValue(t *testing.T) {
12	var input TextInput
13
14	input.Insert('w')
15	input.Insert('ø')
16	input.Insert('k')
17	require.Equal(t, "wøk", input.Value())
18
19	input.Backspace()
20	require.Equal(t, "wø", input.Value())
21
22	input.SetValue("ship")
23	require.Equal(t, "ship", input.Value())
24}
25
26func TestDrawInputLineDrawsPrefixAndValueWithoutCaret(t *testing.T) {
27	frame := renderer.NewFrame(6, 1)
28	style := renderer.DefaultStyle()
29
30	DrawInputLine(frame, 0, "> ", "abc", style)
31
32	require.Equal(t, '>', frame.At(0, 0).Rune)
33	require.Equal(t, ' ', frame.At(1, 0).Rune)
34	require.Equal(t, 'a', frame.At(2, 0).Rune)
35	require.Equal(t, 'b', frame.At(3, 0).Rune)
36	require.Equal(t, 'c', frame.At(4, 0).Rune)
37	require.False(t, frame.At(5, 0).Style.Inverse, "the real terminal cursor is the caret")
38}
39
40func TestInputCaret(t *testing.T) {
41	for _, tt := range []struct {
42		name          string
43		width, rows   int
44		prefix, value string
45		wantCol       int
46		wantOK        bool
47	}{
48		{name: "after value", width: 6, rows: 1, prefix: "> ", value: "abc", wantCol: 5, wantOK: true},
49		{name: "empty value", width: 6, rows: 1, prefix: "/", wantCol: 1, wantOK: true},
50		{name: "wide runes count two columns", width: 8, rows: 1, prefix: "> ", value: "日本", wantCol: 6, wantOK: true},
51		{name: "value fills the line", width: 5, rows: 1, prefix: "> ", value: "abc", wantCol: 5, wantOK: false},
52		{name: "value clipped", width: 4, rows: 1, prefix: "> ", value: "abcdef", wantCol: 8, wantOK: false},
53		{name: "no row", width: 6, rows: 0, prefix: "> ", value: "a", wantCol: 3, wantOK: false},
54	} {
55		t.Run(tt.name, func(t *testing.T) {
56			col, ok := InputCaret(domain.Size{Cols: tt.width, Rows: tt.rows}, tt.prefix, tt.value)
57			require.Equal(t, tt.wantCol, col)
58			require.Equal(t, tt.wantOK, ok)
59		})
60	}
61}
62
63func TestDrawInputLineIgnoresInvalidRow(t *testing.T) {
64	frame := renderer.NewFrame(4, 1)
65
66	DrawInputLine(frame, 2, "> ", "abc", renderer.DefaultStyle())
67
68	require.Equal(t, ' ', frame.At(0, 0).Rune)
69}

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 12

Tags 11

↑↓ moveenter openesc close