model_test.go RawHistoryFolder

1package prompt
2
3import (
4	"strings"
5	"testing"
6
7	renderer "github.com/bnema/vev-vt"
8	"github.com/bnema/vev/internal/domain"
9	"github.com/stretchr/testify/require"
10)
11
12func TestModelPrefillAndEditingClearsError(t *testing.T) {
13	m := New(" Rename session ", "0")
14	require.Equal(t, " Rename session ", m.Title())
15	require.Equal(t, "0", m.Value())
16
17	m.SetError("name already in use")
18	m.Insert('x')
19	require.Equal(t, "0x", m.Value())
20	require.Empty(t, m.errMsg)
21
22	m.SetError("bad")
23	m.Backspace()
24	require.Equal(t, "0", m.Value())
25	require.Empty(t, m.errMsg)
26}
27
28func TestModelRenderDrawsInputAndError(t *testing.T) {
29	m := New(" Rename session ", "work")
30	m.SetError("name already in use")
31
32	frame := m.Render(domain.Size{Cols: 24, Rows: 2})
33
34	require.Equal(t, "> work                  ", promptRowText(frame.Row(0)))
35	require.False(t, frame.At(6, 0).Style.Inverse, "the real terminal cursor is the caret, none is drawn")
36	col, ok := m.Caret(domain.Size{Cols: 24, Rows: 2})
37	require.True(t, ok)
38	require.Equal(t, 6, col, "caret follows prefilled value")
39	require.Equal(t, "name already in use     ", promptRowText(frame.Row(1)))
40	require.True(t, frame.At(0, 1).Style.Inverse, "error line is visually distinct")
41}
42
43func promptRowText(row []renderer.Cell) string {
44	var b strings.Builder
45	for _, c := range row {
46		if c.Rune == 0 {
47			b.WriteRune(' ')
48			continue
49		}
50		b.WriteRune(c.Rune)
51	}
52	return b.String()
53}
54
55func TestModelRenderHandlesTinySize(t *testing.T) {
56	m := New(" Rename session ", "work")
57
58	frame := m.Render(domain.Size{Cols: 0, Rows: 0})
59
60	require.Equal(t, 0, frame.Width)
61	require.Equal(t, 0, frame.Height)
62}
63
64func TestModelRenderStyledFillsBaseAndSelection(t *testing.T) {
65	m := New(" Rename ", "x")
66	base := renderer.Style{Foreground: 1, Background: 2}
67	selection := renderer.Style{Foreground: 3, Background: 4}
68	frame := m.RenderStyled(domain.Size{Cols: 12, Rows: 2}, RenderStyles{Base: base, Selection: selection})
69
70	require.True(t, frame.At(11, 1).Style.Equal(base), "blank filler keeps base surface")
71	require.True(t, frame.At(3, 0).Style.Equal(base), "caret cell keeps base surface under the real cursor")
72}

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