Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

Rewrite Color to struct #55

Merged
merged 3 commits into from
Nov 15, 2020
Merged

Rewrite Color to struct #55

merged 3 commits into from
Nov 15, 2020

Conversation

vladdeSV
Copy link
Owner

Converts the enum Color to struct Color. The enum members have been replaced with static methods.

All features are not implemented (RGB), and there is still some voodoo magic going on with the conversion to ANSI color codes.

@vladdeSV
Copy link
Owner Author

Doing this they way I've done it so far has some side-effects which I have not thought about.

As of now the color implementation is backwards compatible with v2 of scone. The previous enum Color is replaced with struct Color, where the enum members are static methods which return a Color. So far so good.

The reason to why I want to change it to a struct is so I can differentiate between ANSI colors (the default 16 colors) and RGB colors (see #37 for more details) . Previously the enum Color was either an ANSI color, a special case for the default color, or an extra special case to use the same color as in the buffer (which does not really belong here). There was no real way to introduce RGB colors into this enum, so my idea was to store that data in the color itself, along with a default ANSI color.

Although what I have now works, it still has the problems of special "same" color in the list of ANSI colors, and a color now has a state where it's either an ANSI color code or an RGB representation. The current implementation is ambiguous enough so a color can contain both an ANSI color code and RGB data. This should not be the case, as ANSI colors and RGB colors are fundamentally different.

ANSI colors follow a specific, laid out pattern: 8 colors in bright and dark variants, where the terminal emulator decides what that color is supposed to be. RGB colors are specific colors in a range of almost 17 million colors, independent of the setting of the terminal emulator.

This is something which should be respected, in my opinion.

@vladdeSV
Copy link
Owner Author

vladdeSV commented Nov 15, 2020

To continue on my tangent above, I want to explicitly separate a color into three parts

  • ANSI color (4-bit): 8 colors in a bright and dark variant, with the special case for the terminal emulator's default color
  • RGB color (24-bit): One of ~16,8 million colors.
  • same color: A specific case where to use the same color as the cell that is in the buffer. This is only used by scone and does not fit into either of above cases.

I have no good strategy on how to implement this in a good way. I am thinking about colors having nullable members of ANSI and RGB colors, and a flag if it is a "same" color. That implementation might be similar to how it is in this PR, where the color has a state of ansi, rgb, or same.

The members of the color should be ColorState {ansi, rgb, same}, Nullable!AnsiColor, and Nullable!RGBColor.

vladdeSV added a commit that referenced this pull request Nov 15, 2020
@vladdeSV
Copy link
Owner Author

This PR contains initial support to store RGB colors. However, this RGB data is never used.

@vladdeSV vladdeSV merged commit af448f9 into develop Nov 15, 2020
@vladdeSV vladdeSV deleted the change/color-rewrite branch November 15, 2020 18:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant