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
Support conversion from String
to Color
#143
Comments
This might be a "good first issue" too (unless you're planning on knocking it out yourself) |
Oh yeah, I was waiting for some comments, but sure. Anyone should be free to pick it up 🐻 |
I would like to give it a try :) |
Go for it! |
New dep ain't cool. I'm not sure how But if you ask me I would blindly go with that solution. I simply created this issue to get more comments about it. |
I wouldn't use strings if I have enums. Enums are more maintainable. If someone wants easy string to enum conversation, that'd be a separate feature flag, with someone dedicated to maintain it. |
The reason why I want this feature is because you need this conversion from the outside of |
That's the thing... Some may prefer "red", for some it's "RED", while some may prefer hex. There's no "right" conversion system to use. The current serde implementation converts it to "Red", which I think is a good enough default. EDIT: consider both to and from string. EDIT 2: Ah... I see now, one good usecase of this would be to allow conversion from all these different conversion systems into the enum. That might be useful in the sense that the users can choose the style they prefer. But one (probably minor) drawback of this is that, when converting back to string (ser), we have to default to one of the systems. So, if a user writes it as "RED", and when viewing the config (serialized version) sees "Red" or hex code, they'll be pretty confused. |
I think, we can add it as an optional feature and see how many people use it. This way, we don't have to worry about the dependency issue. |
I don't think it needs to be behind a feature:
|
I agree with @sophacles 💯 |
is it okay to use regex or should we go with no additional depency at all ? |
If it's not to hard without regex, no dependency is the preference. |
Problem
In my projects I sometimes need a conversion like this:
Solution
Implement
FromStr
forratatui::style::Color
.An example can be found here.
In the example, I used
rgb
crate for converting HEX values toColor
as well. Since it introduces a new dependency, I'm not sure if we should do that as well.Alternatives
None.
Additional context
I also did something like this in the past: https://github.com/orhun/kmon/blob/66f27006fed614c048469b2511b600d07c8912d6/src/style.rs#L110-L152
The text was updated successfully, but these errors were encountered: