Make Terminal Theme Colour array a typed listed instead #996

Closed
opened 2026-01-30 22:13:21 +00:00 by claunia · 16 comments
Owner

Originally created by @ObsidianPhoenix on GitHub (May 12, 2019).

I've opted to submit this as an issue here as I may be able to effect the change myself, but I wanted to submit it for discussion before doing work/issuing a PR (and I'd probably need a little help finding the relevant place in code).

The current Terminal Theme json requires a color array of 16 RGB values:

{
  "name": "Test",
  "foreground": "#FFFFFF",
  "background": "#000000",
  "colors": [
    "#FFFFFF",
    "#808080",
    "#FFFFFF",
    "#808080",
    "#000000",
    "#000000",
    "#FFA500",
    "#000000",
    "#808080",
    "#FF0000",
    "#0000FF",
    "#FFFF00",
    "#0000FF",
    "#0000FF",
    "#0000FF",
    "#1F1F1F"
  ]
}

These values look like the align with the Vim Terminal Colours. However, its not immediately obvious what the usage of these array elements actually are (not how their index is important).

Since brevity is not really a concern in this case (we're not attempting to transmit this over the wire, etc), I feel like this is simply acting as a barrier to entry for theme designers.

I'd like to suggest replacing this array with a typed collection of properties, e.g.

{
  "name": "Test",
  "foreground": "#FFFFFF",
  "background": "#000000",
  "Black": "#FFFFFF",
  "Red": "#808080",
  "Green": "#FFFFFF",
  "Yellow": "#808080",
  "Blue": "#000000",
  "Purple": "#000000",
  "Cyan": "#FFA500",
  "White": "#000000",
  "BrightBlack": "#808080",
  "BrightRed": "#FF0000",
  "BrightGreen": "#0000FF",
  "BrightYellow": "#FFFF00",
  "BrightBlue": "#0000FF",
  "BrightPurple": "#0000FF",
  "BrightCyan": "#0000FF",
  "BrightWhite": "#1F1F1F"
}

Or a similar structure, e.g.

{
  "name": "Test",
  "foreground": "#FFFFFF",
  "background": "#000000",
  "NormalColors": {
    "Black": "#FFFFFF"
    // ...
  },
  "BrightColors": {
    "Black": "#808080",
    // ...
  }```

Alternative names for the colour items (which might make it more obvious what their intention is are also an option (e.g. ConsoleBlack).

Changing this now will reduce the barrier to entry for theme writers, before a point where too many themes exist to cause a breaking change.

Originally created by @ObsidianPhoenix on GitHub (May 12, 2019). I've opted to submit this as an issue here as I may be able to effect the change myself, but I wanted to submit it for discussion before doing work/issuing a PR (and I'd probably need a little help finding the relevant place in code). The current Terminal Theme json requires a `color` array of 16 RGB values: { "name": "Test", "foreground": "#FFFFFF", "background": "#000000", "colors": [ "#FFFFFF", "#808080", "#FFFFFF", "#808080", "#000000", "#000000", "#FFA500", "#000000", "#808080", "#FF0000", "#0000FF", "#FFFF00", "#0000FF", "#0000FF", "#0000FF", "#1F1F1F" ] } These values look like the align with the [Vim Terminal Colours](https://jeffkreeftmeijer.com/vim-16-color/). However, its not immediately obvious what the usage of these array elements actually are (not how their index is important). Since brevity is not really a concern in this case (we're not attempting to transmit this over the wire, etc), I feel like this is simply acting as a barrier to entry for theme designers. I'd like to suggest replacing this array with a typed collection of properties, e.g. { "name": "Test", "foreground": "#FFFFFF", "background": "#000000", "Black": "#FFFFFF", "Red": "#808080", "Green": "#FFFFFF", "Yellow": "#808080", "Blue": "#000000", "Purple": "#000000", "Cyan": "#FFA500", "White": "#000000", "BrightBlack": "#808080", "BrightRed": "#FF0000", "BrightGreen": "#0000FF", "BrightYellow": "#FFFF00", "BrightBlue": "#0000FF", "BrightPurple": "#0000FF", "BrightCyan": "#0000FF", "BrightWhite": "#1F1F1F" } Or a similar structure, e.g. { "name": "Test", "foreground": "#FFFFFF", "background": "#000000", "NormalColors": { "Black": "#FFFFFF" // ... }, "BrightColors": { "Black": "#808080", // ... }``` Alternative names for the colour items (which might make it more obvious what their intention is are also an option (e.g. `ConsoleBlack`). Changing this now will reduce the barrier to entry for theme writers, before a point where too many themes exist to cause a breaking change.
claunia added the Issue-FeatureHelp WantedArea-Settings labels 2026-01-30 22:13:21 +00:00
Author
Owner

@Jaykul commented on GitHub (May 12, 2019):

Honestly, I'm not really sure I even agree with the choice to store the colors here in the xterm/posix order instead of the ConsoleColor enum order that's used everywhere else in this repo. I mean, wouldn't it make sense to use the ColorTool order?

@Jaykul commented on GitHub (May 12, 2019): Honestly, I'm not really sure I even agree with the choice to store the colors here in the xterm/posix order instead of the ConsoleColor enum order that's used _**everywhere** else_ in this repo. I mean, wouldn't it make sense to use the [ColorTool order](https://github.com/microsoft/Terminal/blob/00bb050826ce15c092b915c3de24c263ce5dc031/src/tools/ColorTool/ColorTool/ColorTable.cs)?
Author
Owner

@DHowett-MSFT commented on GitHub (May 12, 2019):

The terminal is our stake in the ground around being compatible with everyone else first: it is a VT-compliant terminal emulator that works like terminal emulators do. That seems like reason enough to follow the ANSI SGR color ordering over the Windows one.

@DHowett-MSFT commented on GitHub (May 12, 2019): The terminal is our stake in the ground around being compatible with _everyone else_ first: it is a VT-compliant terminal emulator that works like terminal emulators do. That seems like reason enough to follow the ANSI SGR color ordering over the Windows one.
Author
Owner

@MarioLiebisch commented on GitHub (May 12, 2019):

Yeah, I fully agree. A named list is a lot more readable and easier to understand than an array where order actually matters.

@MarioLiebisch commented on GitHub (May 12, 2019): Yeah, I fully agree. A named list is a lot more readable and easier to understand than an array where order actually matters.
Author
Owner

@ObsidianPhoenix commented on GitHub (May 12, 2019):

I'd guess this would be the place to make any changes: dc7fff7ab0/src/cascadia/TerminalApp/ColorScheme.cpp (L120-L129)

On the surface, I think a change to this would be relatively minimal, the result._table[i] = color can more or less remain as-is, it just needs a code block that can translate named properties into their array positions. That would allow a change to clean up the theming without needing to effect a change at lower levels.

@ObsidianPhoenix commented on GitHub (May 12, 2019): I'd guess this would be the place to make any changes: https://github.com/microsoft/Terminal/blob/dc7fff7ab0d698a6ec72cac75dacdf6b5183a63c/src/cascadia/TerminalApp/ColorScheme.cpp#L120-L129 On the surface, I think a change to this would be relatively minimal, the `result._table[i] = color` can more or less remain as-is, it just needs a code block that can translate named properties into their array positions. That would allow a change to clean up the theming without needing to effect a change at lower levels.
Author
Owner

@zadjii-msft commented on GitHub (May 13, 2019):

Yea, naming the properties is probably a good idea. That'll also make it easier when we decide to add a bold color as well.

I'd certainly prefer the first proposal, without the nesting, to the second. @ObsidianPhoenix you're correct, that's the right spot to put them.

@zadjii-msft commented on GitHub (May 13, 2019): Yea, naming the properties is probably a good idea. That'll also make it easier when we decide to add a bold color as well. I'd certainly prefer the first proposal, without the nesting, to the second. @ObsidianPhoenix you're correct, that's the right spot to put them.
Author
Owner

@ObsidianPhoenix commented on GitHub (May 13, 2019):

Thanks. I'm in the middle of creating the commit for it just now. Having some trouble in ToJson though, I think its a pointer issue.

for (int i = 0; i < TABLE_SIZE; i++)
{
	auto current = TABLE_COLORS[i];
	auto color = _table[i];
	auto hexColor = Utils::ColorToHexString(color);
	const auto s = JsonValue::CreateStringValue(hexColor);
			
	jsonObject.Insert(current, s);
}

With this code, all the item values get spat out as "#000000". I'm a C++ newbie, so not sure how to resolve it?

@ObsidianPhoenix commented on GitHub (May 13, 2019): Thanks. I'm in the middle of creating the commit for it just now. Having some trouble in `ToJson` though, I think its a pointer issue. for (int i = 0; i < TABLE_SIZE; i++) { auto current = TABLE_COLORS[i]; auto color = _table[i]; auto hexColor = Utils::ColorToHexString(color); const auto s = JsonValue::CreateStringValue(hexColor); jsonObject.Insert(current, s); } With this code, all the item values get spat out as `"#000000"`. I'm a C++ newbie, so not sure how to resolve it?
Author
Owner

@zadjii-msft commented on GitHub (May 13, 2019):

@ObsidianPhoenix If you create a "draft" PR, I could take a look through the code and see if I can psychic debug what's going wrong.

You might need auto& color = _table[i];, but I really doubt that's it.

@zadjii-msft commented on GitHub (May 13, 2019): @ObsidianPhoenix If you create a "draft" PR, I could take a look through the code and see if I can psychic debug what's going wrong. You might need `auto& color = _table[i];`, but I really doubt that's it.
Author
Owner

@ObsidianPhoenix commented on GitHub (May 13, 2019):

Cheers ^^. I gave your suggestion a go, but it didn't seem to make a difference.

@ObsidianPhoenix commented on GitHub (May 13, 2019): Cheers ^^. I gave your suggestion a go, but it didn't seem to make a difference.
Author
Owner

@ObsidianPhoenix commented on GitHub (May 14, 2019):

@zadjii-msft Ok, it's definitely something local to my machine, rather than the code. I blitzed the entire codebase, uninstalled the app, and rebuilt master from a fresh clone. All the color values are still being set to #000000, even in the original color array.

There has to be an errant file cached somewhere.

@ObsidianPhoenix commented on GitHub (May 14, 2019): @zadjii-msft Ok, it's definitely something local to my machine, rather than the code. I blitzed the entire codebase, uninstalled the app, and rebuilt `master` from a fresh clone. All the color values are still being set to `#000000`, even in the original `color` array. There has to be an errant file cached somewhere.
Author
Owner

@Jaykul commented on GitHub (May 16, 2019):

You cannot make this a named list.
It's not just 16 colors. It should support the full 256 color xterm color palette:

image

@Jaykul commented on GitHub (May 16, 2019): You **cannot** make this a named list. It's not just 16 colors. It **should** support the full 256 color xterm color palette: ![image](https://user-images.githubusercontent.com/192942/57823407-6451de80-7765-11e9-8169-d8c9c56abfe5.png)
Author
Owner

@DHowett-MSFT commented on GitHub (May 16, 2019):

For what it’s worth, I agree. There was somewhat of a discussion about it in #742, which doesn’t seem to have been linked to this issue.

@DHowett-MSFT commented on GitHub (May 16, 2019): For what it’s worth, I agree. There was somewhat of a discussion about it in #742, which doesn’t seem to have been linked to this issue.
Author
Owner

@zadjii-msft commented on GitHub (May 16, 2019):

See, I believe that the number of people changing the default values of the other 240 colors in their settings is going to be vanishingly small compared to the number of people changing the first 16. This change positively improves the user experience of changing the first 16 colors, without preventing us from adding support for the other 240 colors in the future.

As I mentioned in the PR, we could add an optional extendedTable:[] array to a colorscheme and profile, that lets the user override those values if they so chose. I figure'd an array would be fine for the extended values, because you're almost certainly not writing it by hand, and 240 sets of {"color16":"#000000", "color17":"#000004"},... etc, would be insane.

@zadjii-msft commented on GitHub (May 16, 2019): See, I believe that the number of people changing the default values of the other 240 colors in their settings is going to be vanishingly small compared to the number of people changing the first 16. This change positively improves the user experience of changing the first 16 colors, without preventing us from adding support for the other 240 colors in the future. As I mentioned in the PR, we could add an optional `extendedTable:[]` array to a colorscheme and profile, that lets the user override those values if they so chose. I figure'd an array would be fine for the extended values, because you're almost certainly not writing it by hand, and 240 sets of `{"color16":"#000000", "color17":"#000004"},...` etc, would be insane.
Author
Owner

@mdtauk commented on GitHub (May 16, 2019):

So make it possible, but hide it for only the more advanced users.

Perhaps the ability to import a colour scheme, and support the same file types that other terminal's use, with the full range of colours swappable.

@mdtauk commented on GitHub (May 16, 2019): So make it possible, but hide it for only the more advanced users. Perhaps the ability to import a colour scheme, and support the same file types that other terminal's use, with the full range of colours swappable.
Author
Owner

@zadjii-msft commented on GitHub (May 16, 2019):

I have a dream that one day, we'll have just a commandline arg you can pass to wt.exe that'll cause us to look for colortool, and if it finds colortool, it'll use colortool to import all the schemes colortool knows about.

Of course, adding native support for .itermcolors files would be cool too

@zadjii-msft commented on GitHub (May 16, 2019): I have a dream that one day, we'll have just a commandline arg you can pass to `wt.exe` that'll cause us to look for `colortool`, and if it finds colortool, it'll use colortool to import all the schemes colortool knows about. Of course, adding native support for `.itermcolors` files would be cool too
Author
Owner

@mdtauk commented on GitHub (May 16, 2019):

The Windows Terminal settings screen with it's profile editor, could have all the functionality of ColorTool built in. Import and Export a colourscheme and apply it to that profile. Use the XAML colour picker to edit colours, and provide a preview screen.

@mdtauk commented on GitHub (May 16, 2019): The Windows Terminal settings screen with it's profile editor, could have all the functionality of ColorTool built in. Import and Export a colourscheme and apply it to that profile. Use the XAML colour picker to edit colours, and provide a preview screen.
Author
Owner

@DHowett-MSFT commented on GitHub (May 17, 2019):

This should have been closed with #742. If the community in general disagrees, we can continue the discussion on this thread.

@DHowett-MSFT commented on GitHub (May 17, 2019): This should have been closed with #742. If the community in general disagrees, we can continue the discussion on this thread.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#996