okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

nekomimi.petfeat: multiple images, collapsed pastes, and an attachment strip in the prompt6e82811

main
2.2 KiB48 linesraw
1// Which terminals get thumbnails depends on the environment and, under tmux,
2// on the attached client and a tmux option; the e2e suite runs in neither, so
3// a wrong branch here would only show as missing or garbled thumbnails.
4package tui
5
6import "testing"
7
8func TestDetectGraphics(t *testing.T) {
9	for _, test := range []struct {
10		name        string
11		env         map[string]string
12		client      string
13		passthrough string
14		want        graphics
15	}{
16		{name: "kitty", env: map[string]string{"TERM": "xterm-kitty"}, want: graphics{supported: true}},
17		{name: "ghostty", env: map[string]string{"TERM_PROGRAM": "ghostty"}, want: graphics{supported: true}},
18		{name: "plain terminal", env: map[string]string{"TERM": "xterm-256color"}},
19		{name: "tmux in kitty", env: map[string]string{"TMUX": "/tmp/tmux", "TERM": "tmux-256color"}, client: "xterm-kitty", passthrough: "on", want: graphics{supported: true, wrapped: true}},
20		{name: "tmux without passthrough", env: map[string]string{"TMUX": "/tmp/tmux", "KITTY_WINDOW_ID": "1"}, client: "xterm-ghostty", passthrough: "off", want: graphics{hint: "image thumbnails need tmux's allow-passthrough: set -g allow-passthrough on"}},
21		{name: "tmux in a plain terminal", env: map[string]string{"TMUX": "/tmp/tmux", "KITTY_WINDOW_ID": "1"}, client: "xterm-256color", passthrough: "on"},
22	} {
23		t.Run(test.name, func(t *testing.T) {
24			got := detectGraphics(func(key string) string { return test.env[key] }, func(args ...string) string {
25				if args[0] == "display-message" {
26					return test.client
27				}
28				return test.passthrough
29			})
30			if got != test.want {
31				t.Fatalf("got %+v, want %+v", got, test.want)
32			}
33		})
34	}
35}
36
37func TestThumbnailCellsKeepTheAspectInsideTheArea(t *testing.T) {
38	for _, test := range []struct{ width, height, cols, rows int }{
39		{1200, 400, 12, 2}, // wide: full width, few rows
40		{800, 800, 8, 4},   // square: twice as many columns as rows
41		{100, 1000, 1, 4},  // tall: one column
42		{4000, 10, 12, 1},
43	} {
44		if cols, rows := thumbnailCells(test.width, test.height); cols != test.cols || rows != test.rows {
45			t.Errorf("%dx%d: got %dx%d cells, want %dx%d", test.width, test.height, cols, rows, test.cols, test.rows)
46		}
47	}
48}