Code Monkey home page Code Monkey logo

Comments (14)

pythops avatar pythops commented on May 12, 2024 3

I would like to give it a try :)

from ratatui.

sophacles avatar sophacles commented on May 12, 2024 2

I don't think it needs to be behind a feature:

  • Converting from a string based on the variant name is very common, and with the to_lower call to make it case-insensitive, it covers any capitalization preferences. (this is also how the fairly widely used strum crate does it).

  • having a constructor Color::parse_rbg(&str) -> Result<Self, ParseError> that just handles the most common case of #abcdef and doesn't use the Rgb crate as a dependency. This probably covers most TUI cases - I don't expect people to need color conversions or alternate representation (and if they do, they can source the Rgb crate for themselves).

from ratatui.

sophacles avatar sophacles commented on May 12, 2024 2

If it's not to hard without regex, no dependency is the preference.

from ratatui.

sophacles avatar sophacles commented on May 12, 2024

This might be a "good first issue" too (unless you're planning on knocking it out yourself)

from ratatui.

orhun avatar orhun commented on May 12, 2024

Oh yeah, I was waiting for some comments, but sure. Anyone should be free to pick it up 🐻

from ratatui.

orhun avatar orhun commented on May 12, 2024

Go for it!

from ratatui.

pythops avatar pythops commented on May 12, 2024

@orhun

In the example, I used rgb crate for converting HEX values to Color as well. Since it introduces a new dependency, I'm not sure if we should do that as well.

what would be the ideal solution for you ?

from ratatui.

orhun avatar orhun commented on May 12, 2024

New dep ain't cool. I'm not sure how TrueColor conversion would work without it though. I haven't thought about it in depth.

But if you ask me I would blindly go with that solution. I simply created this issue to get more comments about it.

from ratatui.

sayanarijit avatar sayanarijit commented on May 12, 2024

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.

from ratatui.

orhun avatar orhun commented on May 12, 2024

I wouldn't use strings if I have enums. Enums are more maintainable.

The reason why I want this feature is because you need this conversion from the outside of ratatui, for example when you have a configuration file which have a color field and you need to implement De/Serialize for it. In that case, you either going to define your own color enum in your project and manually convert it to ratatui::style::Color OR you will have a string which will somehow support this conversion. I usually go with the latter approach since it has the advantage of true color support. When we use strings, the color can simply be hex code (#000) instead of a name (black) as well.

from ratatui.

sayanarijit avatar sayanarijit commented on May 12, 2024

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.

from ratatui.

sayanarijit avatar sayanarijit commented on May 12, 2024

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.

from ratatui.

orhun avatar orhun commented on May 12, 2024

I agree with @sophacles 💯

from ratatui.

pythops avatar pythops commented on May 12, 2024

is it okay to use regex or should we go with no additional depency at all ?

from ratatui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.