v0.1.33 998a062

image_test.go RawHistoryFolder

1package tui
2
3import (
4	"bytes"
5	"image"
6	"image/color"
7	"image/png"
8	"testing"
9)
10
11func testPNG(t *testing.T, w, h int) []byte {
12	t.Helper()
13	img := image.NewRGBA(image.Rect(0, 0, w, h))
14	for y := 0; y < h; y++ {
15		for x := 0; x < w; x++ {
16			img.Set(x, y, color.RGBA{R: uint8(x), G: uint8(y), B: 128, A: 255})
17		}
18	}
19	var buf bytes.Buffer
20	if err := png.Encode(&buf, img); err != nil {
21		t.Fatal(err)
22	}
23	return buf.Bytes()
24}
25
26func TestRowsForInlineImageRoundsUp(t *testing.T) {
27	t.Setenv("ZOT_CELL_ASPECT", "")
28	data := testPNG(t, 100, 51)
29	got := RowsForInlineImage(data, 10, 0)
30	// 51px high at 10 cells wide with a 2.0 cell aspect is 2.55 rows.
31	// Rounding down to 2 lets following text overlap; we need 3.
32	if got != 3 {
33		t.Fatalf("RowsForInlineImage = %d, want 3", got)
34	}
35}
36
37func TestRowsForInlineImageCellAspectOverride(t *testing.T) {
38	data := testPNG(t, 100, 100)
39	t.Setenv("ZOT_CELL_ASPECT", "1")
40	if got := RowsForInlineImage(data, 10, 0); got != 10 {
41		t.Fatalf("aspect=1 rows = %d, want 10", got)
42	}
43	t.Setenv("ZOT_CELL_ASPECT", "4")
44	if got := RowsForInlineImage(data, 10, 0); got != 3 {
45		t.Fatalf("aspect=4 rows = %d, want 3", got)
46	}
47}
48
49func TestDetectImageProtocolPlaceholderAndVSCode(t *testing.T) {
50	t.Setenv("ZOT_INLINE_IMAGES", "placeholder")
51	if got := DetectImageProtocol(); got != ImageProtocolNone {
52		t.Fatalf("placeholder protocol = %v, want none", got)
53	}
54
55	t.Setenv("ZOT_INLINE_IMAGES", "")
56	t.Setenv("TERM_PROGRAM", "vscode")
57	t.Setenv("KITTY_WINDOW_ID", "1")
58	if got := DetectImageProtocol(); got != ImageProtocolNone {
59		t.Fatalf("vscode auto protocol = %v, want none", got)
60	}
61
62	t.Setenv("ZOT_INLINE_IMAGES", "kitty")
63	if got := DetectImageProtocol(); got != ImageProtocolKitty {
64		t.Fatalf("forced kitty protocol = %v, want kitty", got)
65	}
66}

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