fix(tui): key terminal syntax cache by roles
- commit
- 6b98b2a54f5d6b8ab3974698ba0a7e32b23092b9
- author
- brice · · 2026-08-23 15:48 UTC
- parent
- 037ba94
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +25 -1
M packages/tui/highlight.go +9 -1
| @@ -411,7 +411,15 @@ func (th Theme) terminalSyntaxKeyPart() string { | |||
| 411 | 411 | for _, color := range th.Terminal.Palette { | |
| 412 | 412 | h = hashThemeColor(h, color) | |
| 413 | 413 | } | |
| 414 | - | for _, color := range []TerminalColor{th.Terminal.Foreground, th.Terminal.Background} { | |
| 414 | + | for _, color := range []TerminalColor{ | |
| 415 | + | th.Terminal.Foreground, | |
| 416 | + | th.Terminal.Background, | |
| 417 | + | th.Accent, | |
| 418 | + | th.Muted, | |
| 419 | + | th.Tool, | |
| 420 | + | th.Warning, | |
| 421 | + | th.Error, | |
| 422 | + | } { | |
| 415 | 423 | h = hashThemeColor(h, color) | |
| 416 | 424 | } | |
| 417 | 425 | for _, value := range []bool{th.Terminal.HasForeground, th.Terminal.HasBackground, th.Terminal.TrueColor, th.Terminal.Light, th.Terminal.SchemeKnown} { | |
| @@ -411,7 +411,15 @@ func (th Theme) terminalSyntaxKeyPart() string { | |||||
| 411 | for _, color := range th.Terminal.Palette { | 411 | for _, color := range th.Terminal.Palette { | ||
| 412 | h = hashThemeColor(h, color) | 412 | h = hashThemeColor(h, color) | ||
| 413 | } | 413 | } | ||
| 414 | - | for _, color := range []TerminalColor{th.Terminal.Foreground, th.Terminal.Background} { | 414 | + | for _, color := range []TerminalColor{ |
| 415 | + | th.Terminal.Foreground, | |||
| 416 | + | th.Terminal.Background, | |||
| 417 | + | th.Accent, | |||
| 418 | + | th.Muted, | |||
| 419 | + | th.Tool, | |||
| 420 | + | th.Warning, | |||
| 421 | + | th.Error, | |||
| 422 | + | } { | |||
| 415 | h = hashThemeColor(h, color) | 423 | h = hashThemeColor(h, color) | ||
| 416 | } | 424 | } | ||
| 417 | for _, value := range []bool{th.Terminal.HasForeground, th.Terminal.HasBackground, th.Terminal.TrueColor, th.Terminal.Light, th.Terminal.SchemeKnown} { | 425 | for _, value := range []bool{th.Terminal.HasForeground, th.Terminal.HasBackground, th.Terminal.TrueColor, th.Terminal.Light, th.Terminal.SchemeKnown} { | ||
M packages/tui/highlight_terminal_test.go +16 -0
| @@ -28,6 +28,22 @@ func TestTerminalSyntaxUsesReportedRGBPalette(t *testing.T) { | |||
| 28 | 28 | } | |
| 29 | 29 | } | |
| 30 | 30 | ||
| 31 | + | func TestTerminalSyntaxCacheIncludesSemanticRoles(t *testing.T) { | |
| 32 | + | profile := TerminalProfile{Depth: ColorDepthTrueColor} | |
| 33 | + | first := TerminalTheme(profile) | |
| 34 | + | first.Accent = ColorRGB(1, 2, 3) | |
| 35 | + | second := TerminalTheme(profile) | |
| 36 | + | second.Accent = ColorRGB(4, 5, 6) | |
| 37 | + | ||
| 38 | + | const source = "func terminalSyntaxCacheSentinel() {}" | |
| 39 | + | if got := strings.Join(first.HighlightCode(source, "go"), "\n"); !strings.Contains(got, "\x1b[38;2;1;2;3m") { | |
| 40 | + | t.Fatalf("first output = %q, want first accent", got) | |
| 41 | + | } | |
| 42 | + | if got := strings.Join(second.HighlightCode(source, "go"), "\n"); !strings.Contains(got, "\x1b[38;2;4;5;6m") { | |
| 43 | + | t.Fatalf("second output reused first semantic color: %q", got) | |
| 44 | + | } | |
| 45 | + | } | |
| 46 | + | ||
| 31 | 47 | func TestTerminalSyntaxHonorsCustomOverrides(t *testing.T) { | |
| 32 | 48 | th := TerminalTheme(TerminalProfile{Depth: ColorDepthTrueColor}) | |
| 33 | 49 | th.Syntax.Keyword = "#112233 bold" | |
| @@ -28,6 +28,22 @@ func TestTerminalSyntaxUsesReportedRGBPalette(t *testing.T) { | |||||
| 28 | } | 28 | } | ||
| 29 | } | 29 | } | ||
| 30 | 30 | ||||
| 31 | + | func TestTerminalSyntaxCacheIncludesSemanticRoles(t *testing.T) { | |||
| 32 | + | profile := TerminalProfile{Depth: ColorDepthTrueColor} | |||
| 33 | + | first := TerminalTheme(profile) | |||
| 34 | + | first.Accent = ColorRGB(1, 2, 3) | |||
| 35 | + | second := TerminalTheme(profile) | |||
| 36 | + | second.Accent = ColorRGB(4, 5, 6) | |||
| 37 | + | ||||
| 38 | + | const source = "func terminalSyntaxCacheSentinel() {}" | |||
| 39 | + | if got := strings.Join(first.HighlightCode(source, "go"), "\n"); !strings.Contains(got, "\x1b[38;2;1;2;3m") { | |||
| 40 | + | t.Fatalf("first output = %q, want first accent", got) | |||
| 41 | + | } | |||
| 42 | + | if got := strings.Join(second.HighlightCode(source, "go"), "\n"); !strings.Contains(got, "\x1b[38;2;4;5;6m") { | |||
| 43 | + | t.Fatalf("second output reused first semantic color: %q", got) | |||
| 44 | + | } | |||
| 45 | + | } | |||
| 46 | + | ||||
| 31 | func TestTerminalSyntaxHonorsCustomOverrides(t *testing.T) { | 47 | func TestTerminalSyntaxHonorsCustomOverrides(t *testing.T) { | ||
| 32 | th := TerminalTheme(TerminalProfile{Depth: ColorDepthTrueColor}) | 48 | th := TerminalTheme(TerminalProfile{Depth: ColorDepthTrueColor}) | ||
| 33 | th.Syntax.Keyword = "#112233 bold" | 49 | th.Syntax.Keyword = "#112233 bold" | ||