Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ANSI code and RGB colors #148

Merged
merged 6 commits into from
Oct 31, 2020

Conversation

tomasfarias
Copy link
Contributor

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
Copy link
Contributor Author

tomasfarias commented Oct 31, 2020

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
Copy link
Collaborator

dbrgn commented Oct 31, 2020

I actually prefer the explicit struct with key names 🙂

Copy link
Collaborator

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks pretty straightforward!

Can you also update the README?

(Btw, README is getting a bit long, we should probably use mdbook or something like that in the future...)

src/config.rs Outdated Show resolved Hide resolved
tomasfarias and others added 3 commits October 31, 2020 23:18
@tomasfarias
Copy link
Contributor Author

@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.

README.md Outdated Show resolved Hide resolved
Co-authored-by: Danilo Bargen <mail@dbrgn.ch>
Copy link
Collaborator

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dbrgn dbrgn merged commit 9236f0d into tealdeer-rs:master Oct 31, 2020
@dbrgn dbrgn added this to the v1.5.0 milestone Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Allow 'grey' color
2 participants