inquire icon indicating copy to clipboard operation
inquire copied to clipboard

less verbosity in ui::Color::Rgb{...}

Open adsick opened this issue 3 years ago • 3 comments

I suggest replacing it with ui::Color::Rgb(u8, u8, u8)

adsick avatar Dec 11 '21 13:12 adsick

I agree it has its benefits. Using a struct provides better readability when reading the values (e.g. color.r instead of color.0), but I think only the underlying terminal library actually reads these values, while we create them. While your suggestion makes it much less verbose to create them :)

Would you be willing to make a PR?

mikaelmello avatar Dec 14 '21 11:12 mikaelmello

Oh, I didn't think about color.r that's true. Idk, I'm kinda busy...

adsick avatar Dec 14 '21 16:12 adsick

Would you ever be able to use color.r if the fields are only on one variant of the enum? To get the values out you'd need to do something like if let Color::Rgb{r, g, b} = color { ... } which could just as easily be if let Color::Rgb(r, g, b) = color { ... }.

That said, I quite like the explicitness of naming the fields here even when it might not be necessary. What about adding an rgb(u8, u8, u8) static method to Color that handles the verbosity when creating instances?

tpoliaw avatar Jun 09 '22 14:06 tpoliaw

Both your points are perfect to me. It can get cumbersome on pattern matching and the like but I quite like to be explicit as well. Let's go with the static method.

mikaelmello avatar Aug 19 '22 01:08 mikaelmello