Overview
Wire the Editor's xshd syntax-highlighting colorizer through Terminal.Gui's Scheme / VisualRole system, so the Editor participates in TG's ThemeManager-driven theme story alongside MarkdownCodeBlock and the new Code view. Closes #99 (theme switching for syntax highlighting) and #128 (unreadable JSON colors on dark terminals).
This is the Editor-side consumer of a larger cross-repo plan. The TG work happens first; this issue captures the Editor work that follows.
Plan & spec
The full plan, including phase ordering, decision log, palette tables, file lists, definitions of done, and out-of-scope notes, lives in specs/syntax-theme/spec.md on the develop branch. Implementation will happen on the existing code-themes branch and worktree at ../Editor-code-themes.
Cross-repo dependencies
This issue is blocked by both:
- gui-cs/Terminal.Gui#5310 — adds the
ConfigurationManager / Scheme / Theme benchmark baseline TG needs before code-role storage can be evaluated for regression.
- gui-cs/Terminal.Gui#5311 — adds the 12
VisualRole.Code* entries, matching Scheme storage, populated Dark / Light themes, a new public Code view, and unified markdown-highlighter routing. This issue's PR bumps <TerminalGuiVersion> to the release that ships #5311.
Implementation on the code-themes branch in this repo can begin in parallel with TG #5311 — anything that references VisualRole.CodeXxx won't compile until a TG release with #5311 ships, but the role-mapping table, xshd loader plumbing, colorizer rewrite, and tests can all be drafted against the agreed-on enum names.
Scope (this repo, Phase 2 in the spec)
Bridge xshd named colors to VisualRoles
New src/Terminal.Gui.Editor/Highlighting/XshdRoleMap.cs — a built-in Dictionary<string, VisualRole> keyed by xshd <Color name="..."> values, covering common cross-language names (Comment, Keyword/Keywords, String/Char/Character, NumberLiteral/Digits/Number, Operators, Preprocessor, Punctuation, MethodCall/MethodName, ValueTypeKeywords/ReferenceTypeKeywords/DataTypes, FieldName/Variable, TrueFalse/Bool/Null/NullOrValueKeywords, JavaDocTags/KnownDocTags/Attributes, plus the language-categorized variants — see spec §6.2 for the full draft table). Names absent from the table fall through to the xshd-declared color (today's behavior).
Let xshd entries override the bridge per-color
Add an optional category="..." attribute to xshd's <Color> element and a VisualRole? Role property on the runtime HighlightingColor. At load time, populate Role from category= if present; else from XshdRoleMap.TryGetRole(name); else null. Log the new xshd attribute as an intentional fork addition in third_party/AvaloniaEdit/UPSTREAM.md.
Route the colorizer through the active scheme
Rewrite HighlightingColorizer.ToAttribute. Resolution order:
- If
color.Role is non-null AND the editor's current scheme has an explicit (non-derived) Attribute for that role, return it.
- Else fall back to xshd's declared
Foreground paired with the editor's scheme background.
- Else return the editor's default attribute.
The constructor gains a Func<VisualRole, Attribute>? getRoleAttribute parameter, supplied by Editor as role => GetAttributeForRole(role).
Retire Editor.UseThemeBackground
Remove the property at src/Terminal.Gui.Editor/Editor.cs:231-245, the _useThemeBackground field on HighlightingColorizer, and the useThemeBackground parameter on VisualLineBuildContext. The theme decides backgrounds now; pre-alpha — no compat shim.
Repaint on theme changes
Editor hooks ThemeManager.ThemeChanged (and SchemeChanged if exposed). On either event, invalidate visual-line caches and redraw.
Add a Theme switcher to the ted demo
examples/ted/TedApp.cs gains a Theme Shortcut in the status bar next to the existing Language shortcut. Click cycles ThemeManager.Theme across the TG-shipped theme names; title updates to the current theme.
Files
See spec §"Files in Scope" → "Editor repo (Phase 2)" for the full list. Headlines:
Directory.Build.props — bump <TerminalGuiVersion>
src/Terminal.Gui.Editor/Highlighting/XshdRoleMap.cs — NEW
src/Terminal.Gui.Editor/Highlighting/HighlightingColor.cs — add VisualRole? Role
src/Terminal.Gui.Editor/Highlighting/Xshd/XshdColor.cs — add Category property
src/Terminal.Gui.Editor/Highlighting/Xshd/V2Loader.cs (or equivalent) — read category=
src/Terminal.Gui.Editor/Rendering/HighlightingColorizer.cs — rewrite ToAttribute
src/Terminal.Gui.Editor/Rendering/VisualLineBuildContext.cs — drop useThemeBackground param
src/Terminal.Gui.Editor/Editor.cs — remove UseThemeBackground; wire theme/scheme-changed handlers
examples/ted/TedApp.cs — add Theme Shortcut to status bar
tests/Terminal.Gui.Editor.Tests/HighlightingTests.cs — new tests
tests/Terminal.Gui.Editor.IntegrationTests/ — theme-swap smoke test
third_party/AvaloniaEdit/UPSTREAM.md — log category= addition
Definition of Done
Out of Scope
See spec §"Out of Scope". Highlights:
- Editing the 14 xshd resource files. The role table covers them. Per-language
category= overrides only if a specific case proves wrong; logged in UPSTREAM.md per fork policy when made.
- Per-Editor
HighlightingTheme property. TG's ThemeManager.Theme is the single switch.
- TextMate grammar palette bridge for Editor. Ships with the post-alpha textmate-grammars work (per DEC-002), not here.
- Themable Markdown structural tokens (
Markup* role family). Deferred until a concrete consumer arises.
- Bold/italic/underline overrides via theme. Future enhancement.
Working branch
Implementation work happens on branch code-themes, worktree at ../Editor-code-themes. The spec also lives there as specs/syntax-theme/spec.md. Push and PR when TG #5311 ships and the Editor work is ready for review.
Overview
Wire the
Editor's xshd syntax-highlighting colorizer through Terminal.Gui'sScheme/VisualRolesystem, so theEditorparticipates in TG'sThemeManager-driven theme story alongsideMarkdownCodeBlockand the newCodeview. Closes #99 (theme switching for syntax highlighting) and #128 (unreadable JSON colors on dark terminals).This is the Editor-side consumer of a larger cross-repo plan. The TG work happens first; this issue captures the Editor work that follows.
Plan & spec
The full plan, including phase ordering, decision log, palette tables, file lists, definitions of done, and out-of-scope notes, lives in
specs/syntax-theme/spec.mdon thedevelopbranch. Implementation will happen on the existingcode-themesbranch and worktree at../Editor-code-themes.Cross-repo dependencies
This issue is blocked by both:
ConfigurationManager/Scheme/Themebenchmark baseline TG needs before code-role storage can be evaluated for regression.VisualRole.Code*entries, matchingSchemestorage, populatedDark/Lightthemes, a new publicCodeview, and unified markdown-highlighter routing. This issue's PR bumps<TerminalGuiVersion>to the release that ships #5311.Implementation on the
code-themesbranch in this repo can begin in parallel with TG #5311 — anything that referencesVisualRole.CodeXxxwon't compile until a TG release with #5311 ships, but the role-mapping table, xshd loader plumbing, colorizer rewrite, and tests can all be drafted against the agreed-on enum names.Scope (this repo, Phase 2 in the spec)
Bridge xshd named colors to VisualRoles
New
src/Terminal.Gui.Editor/Highlighting/XshdRoleMap.cs— a built-inDictionary<string, VisualRole>keyed by xshd<Color name="...">values, covering common cross-language names (Comment,Keyword/Keywords,String/Char/Character,NumberLiteral/Digits/Number,Operators,Preprocessor,Punctuation,MethodCall/MethodName,ValueTypeKeywords/ReferenceTypeKeywords/DataTypes,FieldName/Variable,TrueFalse/Bool/Null/NullOrValueKeywords,JavaDocTags/KnownDocTags/Attributes, plus the language-categorized variants — see spec §6.2 for the full draft table). Names absent from the table fall through to the xshd-declared color (today's behavior).Let xshd entries override the bridge per-color
Add an optional
category="..."attribute to xshd's<Color>element and aVisualRole? Roleproperty on the runtimeHighlightingColor. At load time, populateRolefromcategory=if present; else fromXshdRoleMap.TryGetRole(name); else null. Log the new xshd attribute as an intentional fork addition inthird_party/AvaloniaEdit/UPSTREAM.md.Route the colorizer through the active scheme
Rewrite
HighlightingColorizer.ToAttribute. Resolution order:color.Roleis non-null AND the editor's current scheme has an explicit (non-derived)Attributefor that role, return it.Foregroundpaired with the editor's scheme background.The constructor gains a
Func<VisualRole, Attribute>? getRoleAttributeparameter, supplied byEditorasrole => GetAttributeForRole(role).Retire
Editor.UseThemeBackgroundRemove the property at
src/Terminal.Gui.Editor/Editor.cs:231-245, the_useThemeBackgroundfield onHighlightingColorizer, and theuseThemeBackgroundparameter onVisualLineBuildContext. The theme decides backgrounds now; pre-alpha — no compat shim.Repaint on theme changes
EditorhooksThemeManager.ThemeChanged(andSchemeChangedif exposed). On either event, invalidate visual-line caches and redraw.Add a Theme switcher to the ted demo
examples/ted/TedApp.csgains aThemeShortcutin the status bar next to the existingLanguageshortcut. Click cyclesThemeManager.Themeacross the TG-shipped theme names; title updates to the current theme.Files
See spec §"Files in Scope" → "Editor repo (Phase 2)" for the full list. Headlines:
Directory.Build.props— bump<TerminalGuiVersion>src/Terminal.Gui.Editor/Highlighting/XshdRoleMap.cs— NEWsrc/Terminal.Gui.Editor/Highlighting/HighlightingColor.cs— addVisualRole? Rolesrc/Terminal.Gui.Editor/Highlighting/Xshd/XshdColor.cs— addCategorypropertysrc/Terminal.Gui.Editor/Highlighting/Xshd/V2Loader.cs(or equivalent) — readcategory=src/Terminal.Gui.Editor/Rendering/HighlightingColorizer.cs— rewriteToAttributesrc/Terminal.Gui.Editor/Rendering/VisualLineBuildContext.cs— dropuseThemeBackgroundparamsrc/Terminal.Gui.Editor/Editor.cs— removeUseThemeBackground; wire theme/scheme-changed handlersexamples/ted/TedApp.cs— addThemeShortcutto status bartests/Terminal.Gui.Editor.Tests/HighlightingTests.cs— new teststests/Terminal.Gui.Editor.IntegrationTests/— theme-swap smoke testthird_party/AvaloniaEdit/UPSTREAM.md— logcategory=additionDefinition of Done
<TerminalGuiVersion>bumped to that releasedotnet run --project tests/Terminal.Gui.Editor.Testspasses incl. new tests:XshdRoleMapcovers the common cross-language names from spec §6.2category=attribute on an xshd<Color>wins over the default tabledotnet run --project tests/Terminal.Gui.Editor.IntegrationTestspasses incl. theme-swap smoke testted foo.csandted foo.jsonare readable on both dark and light terminals (manual)ThemeManager.Themeand lines re-render liveEditor.UseThemeBackgroundremoved; no callers remaindotnet format Terminal.Gui.Editor.slnx --exclude third_party/ --verify-no-changescleandotnet jb cleanupcode Terminal.Gui.Editor.slnx --profile="TG.Editor Full Cleanup"cleanOut of Scope
See spec §"Out of Scope". Highlights:
category=overrides only if a specific case proves wrong; logged inUPSTREAM.mdper fork policy when made.HighlightingThemeproperty. TG'sThemeManager.Themeis the single switch.Markup*role family). Deferred until a concrete consumer arises.Working branch
Implementation work happens on branch
code-themes, worktree at../Editor-code-themes. The spec also lives there asspecs/syntax-theme/spec.md. Push and PR when TG #5311 ships and the Editor work is ready for review.