ziglibs / ansi-term

Zig library for dealing with ANSI terminals
MIT License
68 stars 7 forks source link

Add Grey to Color type #8

Closed data-man closed 3 years ago

data-man commented 4 years ago

Another idea: rename it to GreyRGB and add 24 grayscale colors from 256-color palette (232-255 indexes).

joachimschmidt557 commented 4 years ago

I had a look at other implementations for this.

https://github.com/ogham/rust-ansi-term/blob/ff7eba98d55ad609c7fcc8c7bb0859b37c7545cc/src/style.rs#L304

Here, it seems they just included the grey colors into the 256 colors and added that as a doc comment. What do you think @data-man ? Should there maybe exist a conversion function from greyscale to the appropiate values in the 256 colors?

data-man commented 4 years ago

@joachimschmidt557 I have another cool example :smile: https://github.com/rocketsman/colorful/blob/master/src/core/colors.rs#L266

I have checked many other implementations in different languages and noticed that some libraries outputs White (FG/BG Code 37/47) as 97/107. And White named as Grey.

I think it's correct.

https://en.wikipedia.org/wiki/ANSI_escape_code#Colors has pretty table for comparison.

joachimschmidt557 commented 4 years ago

Hmm, that example uses a large enum for the 256 colors which includes the shades of grey. Should we use that?

data-man commented 4 years ago

@joachimschmidt557

Should we use that?

Why not? IMO Grey50 is easier to remember than RGB(128, 128, 128). And less typing. :)

data-man commented 3 years ago

I'm still waiting for your reply... :grinning:

Q:

Should we use that?

A:

Why not?

data-man commented 3 years ago

But the most important question is:

some libraries outputs White (FG/BG Code 37/47) as 97/107. And White named as Grey. I think it's correct.

Thoughts?

joachimschmidt557 commented 3 years ago

I have checked many other implementations in different languages and noticed that some libraries outputs White (FG/BG Code 37/47) as 97/107. And White named as Grey.

Ultimately, it's just a naming scheme. According to Wikipedia, 37 is also called white and 97 is called bright white. I think the name white for 37 is okay.

Regarding the large enums for color names, this can be implemented, but I'd prefer a new file called color_names.zig or similar where color names are mapped to the ANSI colors.

data-man commented 3 years ago

Ok! :)

but I'd prefer a new file called color_names.zig or similar where color names are mapped to the ANSI colors.

:+1:

Now we can create enums in comptime by @Type. Just an idea...

data-man commented 3 years ago

Are you ok with other color representation? HSL, HSV, CMYK, ...

joachimschmidt557 commented 3 years ago

Are you ok with other color representation? HSL, HSV, CMYK, ...

I think stuff like this is out of scope for this library. The basic colors or the 8-bit colors can vary from terminal from terminal and even within one terminal users can have different color themes. Converting RGB (24-bit colors) into HSL, HSV, ... and vice versa should be the job of another library focusing on colors, color spaces, conversions and other color operations.