v0.3.70 5bef29b

clipboard_linux_test.go RawHistoryFolder

1//go:build linux
2
3package tui
4
5import (
6	"bytes"
7	"os"
8	"path/filepath"
9	"testing"
10)
11
12func writeFakeLinuxClipboard(t *testing.T, name, script string) {
13	t.Helper()
14	path := filepath.Join(t.TempDir(), name)
15	if err := os.WriteFile(path, []byte("#!/bin/sh\n"+script), 0o700); err != nil {
16		t.Fatal(err)
17	}
18	t.Setenv("PATH", filepath.Dir(path))
19}
20
21func TestReadClipboardImagePNGWayland(t *testing.T) {
22	fixture := filepath.Join(t.TempDir(), "image.png")
23	want := testClipboardPNG(t)
24	if err := os.WriteFile(fixture, want, 0o600); err != nil {
25		t.Fatal(err)
26	}
27	t.Setenv("CLIPBOARD_IMAGE_FIXTURE", fixture)
28	t.Setenv("WAYLAND_DISPLAY", "wayland-0")
29	t.Setenv("DISPLAY", "")
30	writeFakeLinuxClipboard(t, "wl-paste", `
31if [ "$1" = "--list-types" ]; then
32    printf 'text/plain\nimage/png\n'
33else
34    /bin/cat "$CLIPBOARD_IMAGE_FIXTURE"
35fi
36`)
37
38	path, got, ok, err := ReadClipboardImagePNG()
39	if err != nil {
40		t.Fatal(err)
41	}
42	if path != "" || !ok {
43		t.Fatalf("path = %q, ok = %v", path, ok)
44	}
45	if !bytes.Equal(got, want) {
46		// Normalization may choose a different valid PNG representation, so
47		// compare dimensions when the encoded bytes differ.
48		if gotW, gotH := ImageDimensions(got); gotW != 2 || gotH != 2 {
49			t.Fatalf("normalized image dimensions = %dx%d", gotW, gotH)
50		}
51	}
52}
53
54func TestReadClipboardImagePNGX11(t *testing.T) {
55	fixture := filepath.Join(t.TempDir(), "image.png")
56	if err := os.WriteFile(fixture, testClipboardPNG(t), 0o600); err != nil {
57		t.Fatal(err)
58	}
59	t.Setenv("CLIPBOARD_IMAGE_FIXTURE", fixture)
60	t.Setenv("WAYLAND_DISPLAY", "")
61	t.Setenv("DISPLAY", ":1")
62	writeFakeLinuxClipboard(t, "xclip", `
63if [ "$4" = "TARGETS" ]; then
64    printf 'TARGETS\nimage/png\n'
65else
66    /bin/cat "$CLIPBOARD_IMAGE_FIXTURE"
67fi
68`)
69
70	_, got, ok, err := ReadClipboardImagePNG()
71	if err != nil {
72		t.Fatal(err)
73	}
74	if !ok || len(got) == 0 {
75		t.Fatalf("ok = %v, len(data) = %d", ok, len(got))
76	}
77}
78
79func TestReadClipboardImagePNGNoImageFallsBack(t *testing.T) {
80	t.Setenv("WAYLAND_DISPLAY", "wayland-0")
81	t.Setenv("DISPLAY", "")
82	writeFakeLinuxClipboard(t, "wl-paste", `
83if [ "$1" = "--list-types" ]; then
84    printf 'text/plain;charset=utf-8\n'
85    exit 0
86fi
87exit 9
88`)
89
90	_, data, ok, err := ReadClipboardImagePNG()
91	if err != nil {
92		t.Fatal(err)
93	}
94	if ok || data != nil {
95		t.Fatalf("ok = %v, data = %v", ok, data)
96	}
97}
98
99func TestReadClipboardImagePNGRejectsMalformedData(t *testing.T) {
100	t.Setenv("WAYLAND_DISPLAY", "wayland-0")
101	t.Setenv("DISPLAY", "")
102	writeFakeLinuxClipboard(t, "wl-paste", `
103if [ "$1" = "--list-types" ]; then
104    printf 'image/png\n'
105else
106    printf 'not a png'
107fi
108`)
109
110	if _, _, ok, err := ReadClipboardImagePNG(); err == nil || ok {
111		t.Fatalf("ok = %v, err = %v", ok, err)
112	}
113}
114
115func TestPreferredClipboardImageMIME(t *testing.T) {
116	mime, ok := preferredClipboardImageMIME("text/plain\nimage/jpeg\nimage/png\n")
117	if !ok || mime != "image/png" {
118		t.Fatalf("mime = %q, ok = %v", mime, ok)
119	}
120	if mime, ok := preferredClipboardImageMIME("text/plain\ntext/html\n"); ok {
121		t.Fatalf("mime = %q, want no image MIME", mime)
122	}
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