-
Couldn't load subscription status.
- Fork 725
Description
As discussed in:
- Master Issue for Updating Color/Attribute System #457
- Add Non-Color Attributes (Bold, Italic, Underline, etc.) to
Attributes#4058 - Attribute System Should honor terminal settings #2381
The names ColorScheme and Colors in Terminal.Gui are misleading because they imply color-only functionality, yet Attributes within ColorScheme will soon support non-color styles (e.g., Bold, Italic, per #4058). The static Colors dictionary (Terminal.Gui.Colors.ColorSchemes) causes thread-safety issues and lacks type safety, making it unsuitable for modern theme management. I propose:
-
Rename
ColorSchemetoSchemeto reflect its role in defining both color and non-color visual styles. -
Remove
Colorsand migrate its functionality toConfigurationManager.Themes, leveraging Terminal.Gui’s JSON-driven theme management system.
This issue focuses on these naming and structural changes, keeping #457 as the master issue for the broader ColorSchemes redesign, including per-view defaults and terminal settings (#2381). Backward compatibility for Colors is not required, simplifying the migration.
Current State
-
ColorSchemeis a class definingAttributes(Normal, HotNormal, Focus, HotFocus, Disabled) used by views for styling. -
Colorsis a static dictionary with string keys (e.g., "Base", "Dialog", "Menu", "Error"), which is prone to threading issues and not configurable by users. -
ConfigurationManager.Themesmanages themes (e.g., “Light”, “Dark”) as a non-static dictionary ofColorSchemeinstances, loaded from JSON configs (e.g.,.tui/config.json, embeddedconfig.json). It supports user-defined themes, runtime overrides (e.g.,ConfigurationManager.RuntimeConfig = """{ "Theme": "Light" }"""), and a robust API for theme management (e.g., adding, retrieving, applying themes). -
Current
ConfigurationManager.ThemesJSON structure:
{
"Dark": {
"ColorSchemes": [
{
"TopLevel": {
"Normal": {
// Color and attribute definitions
}
...Proposed Changes
-
Rename
ColorSchemetoScheme:-
Update the class name to
Schemefor clarity and brevity. -
Refactor all references in the codebase (e.g.,
View.ColorScheme,ConfigurationManager.Themes,ThemeManager). -
Update the
tui-config-schema.jsonto useSchemesinstead ofColorSchemesin theme definitions (https://gui-cs.github.io/Terminal.GuiV2Docs/schemas/tui-config-schema.json).
-
-
Remove
Colorsand Migrate toConfigurationManager.Themes:-
Eliminate the static
Terminal.Gui.Colorsclass and itsColorSchemesdictionary. -
Migrate default schemes (Base, Dialog, Menu, Error) to
ConfigurationManager.Themes, storing them asSchemeinstances in the embeddedconfig.jsonor user.tuiconfigs. -
Update
ThemeManagerto store and manageSchemeinstances, ensuring seamless integration with the existing theme management API. -
Example updated JSON structure:
-
{
"Dark": {
"Schemes": [
{
"TopLevel": {
"Normal": {
// Color and attribute definitions
}
...-
Support Theme Inheritance:
- Ensure
ConfigurationManager.Themessupports theme inheritance, where views default to theirSuperView’s theme if unspecified, per Master Issue for Updating Color/Attribute System #457’s hierarchy model.
- Ensure
-
Support Future Terminal Settings:
- Design
ConfigurationManager.Themesto integrate with user terminal colors (e.g.,$PSStyleor$TERMsettings) when implemented in Attribute System Should honor terminal settings #2381, though this is out of scope here.
- Design
-
Documentation and Testing:
-
Update documentation, samples (e.g., UICatalog, Example.cs), and API docs to reflect
SchemeandConfigurationManager.Themes. -
Fix unit tests to remove
Colorsdependencies and validateThemeManagerintegration.
-
Benefits
-
Clarifies that
Schemesupports both colors and non-color attributes (aligning with Add Non-Color Attributes (Bold, Italic, Underline, etc.) toAttributes#4058). -
Resolves threading issues by replacing static
ColorswithConfigurationManager’s non-static, JSON-driven system. -
Enables user-defined themes via
.tuiconfigs, enhancing flexibility and customization. -
Supports Master Issue for Updating Color/Attribute System #457’s goal of a consistent, scalable styling system and prepares for Attribute System Should honor terminal settings #2381’s terminal settings integration.
Tasks
-
Refactor
ColorSchemetoSchemeacross the codebase and JSON schema. -
Remove
Terminal.Gui.Colorsand migrate its schemes toConfigurationManager.Themes. -
Update documentation, samples, and UICatalog to use
SchemeandConfigurationManager.Themes. -
Fix unit tests to eliminate
Colorsdependencies and validateThemeManagerintegration.
Related Issues
-
Add Non-Color Attributes (Bold, Italic, Underline, etc.) to
Attributes#4058: Add non-color attributes toAttributes(supporting styles like Bold, Italic). -
Master Issue for Updating Color/Attribute System #457: Master issue for
ColorSchemesredesign, including per-view defaults and terminal settings. -
Attribute System Should honor terminal settings #2381: Honor user terminal settings (mappings to
Schemeattributes). -
Truecolors (direct RGB colors) support #48: Truecolors support (relevant for advanced color handling).
Open Questions
-
Are there edge cases in
ThemeManagerthat need addressing forSchememigration? -
Should
ConfigurationManager.Themesinclude additional validation for user-defined themes? -
Should the JSON structure for
Schemesbe flattened or simplified (e.g., remove nested array)?
Community feedback on the rename, migration approach, and ThemeManager integration is welcome!
Metadata
Metadata
Assignees
Labels
Type
Projects
Status