tealdeer-rs / tealdeer

A very fast implementation of tldr in Rust.
https://tealdeer-rs.github.io/tealdeer/
Apache License 2.0
4.17k stars 123 forks source link

Add support for ANSI code and RGB colors #148

Closed tomasfarias closed 3 years ago

tomasfarias commented 3 years ago

Closes #147

Allows defining colors as ANSI codes or RGB in config.toml e.g.:

[style.command_name]
background = { ansi = 7 }
foreground =  { rgb = { r = 255, g = 51, b = 255 } }
tomasfarias commented 3 years ago

FYI, my first attempt implemented RGB variant as a tuple struct:

pub enum RawColor {
    ...
    RGB(u8, u8, u8),
}

Since I expected the config to use an array, for example foreground = { rgb = [255, 10, 125] }. But apparently toml deserializing expects a table for tuple structs, not an array, so in order for deserialization to work the config would have had to look like foreground = { rgb = { 0 = 255, 1 = 10, 2 = 125} }.

For that reason, I went with a regular struct as I think having r, g and b as the keys is more intuitive than 0, 1 and 2: foreground = { rgb = { r = 255, g = 10, b = 125} }

Edit: the { rgb = [255, 10, 125] } format could be supported by RGB([u8; 3]). I'm neutral between { rgb = [255, 10, 125] } and { rgb = { r = 255, g = 10, b = 125} }, so would like some input to decide.

dbrgn commented 3 years ago

I actually prefer the explicit struct with key names :slightly_smiling_face:

tomasfarias commented 3 years ago

@dbrgn Thanks for the review! Let me know if the README update looks fine, or if there's anything more I should add or change.