v0.2.41 1a24a20

theme_loader_test.go RawHistoryFolder

1package tui
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7)
8
9func TestLoadThemeAllowsPartialColorOverrides(t *testing.T) {
10	home := t.TempDir()
11	if err := os.MkdirAll(filepath.Join(home, "themes"), 0o755); err != nil {
12		t.Fatal(err)
13	}
14	path := filepath.Join(home, "themes", "partial.json")
15	if err := os.WriteFile(path, []byte(`{"colors":{"dark":{"accent":204}}}`), 0o644); err != nil {
16		t.Fatal(err)
17	}
18
19	th, name, err := LoadThemeFromHome(home, "partial", Dark)
20	if err != nil {
21		t.Fatal(err)
22	}
23	if name != "partial" {
24		t.Fatalf("name = %q, want partial", name)
25	}
26	if th.Accent != 204 {
27		t.Fatalf("accent = %d, want 204", th.Accent)
28	}
29	if th.FG != Dark.FG {
30		t.Fatalf("fg = %d, want inherited %d", th.FG, Dark.FG)
31	}
32	if len(th.SpinnerFrames) == 0 || len(th.SpinnerMessages) == 0 {
33		t.Fatal("spinner defaults should be inherited")
34	}
35}
36
37func TestLoadThemeAllowsSpinnerOnlyTopLevelOverrides(t *testing.T) {
38	home := t.TempDir()
39	if err := os.MkdirAll(filepath.Join(home, "themes"), 0o755); err != nil {
40		t.Fatal(err)
41	}
42	path := filepath.Join(home, "themes", "spinner.json")
43	if err := os.WriteFile(path, []byte(`{"spinner_frames":[".","o"],"spinner_messages":["working"],"spinner_interval_ms":200}`), 0o644); err != nil {
44		t.Fatal(err)
45	}
46
47	th, _, err := LoadThemeFromHome(home, "spinner", Dark)
48	if err != nil {
49		t.Fatal(err)
50	}
51	if got := len(th.SpinnerFrames); got != 2 {
52		t.Fatalf("spinner frame count = %d, want 2", got)
53	}
54	if th.SpinnerFrames[1] != "o" || th.SpinnerMessages[0] != "working" || th.SpinnerIntervalMS != 200 {
55		t.Fatalf("spinner overrides not applied: %#v %#v %d", th.SpinnerFrames, th.SpinnerMessages, th.SpinnerIntervalMS)
56	}
57	if th.Accent != Dark.Accent {
58		t.Fatalf("accent = %d, want inherited %d", th.Accent, Dark.Accent)
59	}
60}
61
62func TestLoadThemeFallsBackToDarkWhenLightModeMissing(t *testing.T) {
63	home := t.TempDir()
64	if err := os.MkdirAll(filepath.Join(home, "themes"), 0o755); err != nil {
65		t.Fatal(err)
66	}
67	path := filepath.Join(home, "themes", "darkonly.json")
68	if err := os.WriteFile(path, []byte(`{"colors":{"dark":{"spinner_frames":["◢","◣","◤","◥"],"spinner_messages":["working"],"spinner_interval_ms":120}}}`), 0o644); err != nil {
69		t.Fatal(err)
70	}
71
72	th, _, err := LoadThemeFromHome(home, "darkonly", Light)
73	if err != nil {
74		t.Fatal(err)
75	}
76	if len(th.SpinnerFrames) != 4 || th.SpinnerFrames[0] != "◢" {
77		t.Fatalf("spinner frames = %#v, want dark fallback frames", th.SpinnerFrames)
78	}
79	if len(th.SpinnerMessages) != 1 || th.SpinnerMessages[0] != "working" {
80		t.Fatalf("spinner messages = %#v, want dark fallback message", th.SpinnerMessages)
81	}
82	if th.SpinnerIntervalMS != 120 {
83		t.Fatalf("spinner interval = %d, want 120", th.SpinnerIntervalMS)
84	}
85	if th.FG != Light.FG {
86		t.Fatalf("fg = %d, want inherited light fg %d", th.FG, Light.FG)
87	}
88}
89
90func TestLoadThemeAllowsSharedColorsOverrides(t *testing.T) {
91	home := t.TempDir()
92	if err := os.MkdirAll(filepath.Join(home, "themes"), 0o755); err != nil {
93		t.Fatal(err)
94	}
95	path := filepath.Join(home, "themes", "shared.json")
96	if err := os.WriteFile(path, []byte(`{"colors":{"accent":204,"spinner_messages":["ship"]}}`), 0o644); err != nil {
97		t.Fatal(err)
98	}
99
100	th, _, err := LoadThemeFromHome(home, "shared", Light)
101	if err != nil {
102		t.Fatal(err)
103	}
104	if th.Accent != 204 {
105		t.Fatalf("accent = %d, want 204", th.Accent)
106	}
107	if len(th.SpinnerMessages) != 1 || th.SpinnerMessages[0] != "ship" {
108		t.Fatalf("spinner messages = %#v, want ship", th.SpinnerMessages)
109	}
110	if th.FG != Light.FG {
111		t.Fatalf("fg = %d, want inherited %d", th.FG, Light.FG)
112	}
113}

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