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

Allow for optional colors #611

Closed
wants to merge 3 commits into from
Closed

Allow for optional colors #611

wants to merge 3 commits into from

Conversation

spenserblack
Copy link
Collaborator

@spenserblack spenserblack commented Mar 14, 2022

This was originally going to be a quick and painless change using an OptionalColor type and .into(), but it quickly turned into way more changes than expected 😅 Hopefully nothing has broken.

The last commit is TEMP because it seems like strum is naively using None instead of Option::None in its macro definition, breaking that commit. spenserblack@5142c5f is OK to review, though. I'll make a PR to strum, but, assuming spenserblack@5142c5f is good, it's ready to be merged if we don't want to wait.

Edit: Nevermind, tests fail on that commit.

Edit2: Force-pushed, 0ef1c64 should be OK.

Edit3: Peternator7/strum#214 merged, on next release this whole PR should be ready to review.

Edit4: No need for a new strum release. I realized that Fg is a more descriptive variant than None.

@o2sh
Copy link
Owner

o2sh commented Mar 17, 2022

Is this really a good idea to alter the logo's original colour palette? IMO, this may help a small portion of users on light theme terminals in terms of readability but they will lose in terms of aesthetics.

@spenserblack
Copy link
Collaborator Author

Well the main reason was to allow the logo's "white" color to just be the text color. I agree that this is a massive change, but we've gotten a few notes that onefetch doesn't look good on light terminals, and one user pointed out that

neofetch has no problem with this

(Source: #33 (comment))

It appears that Neofetch doesn't really use the white color. When the default color is white, or the selected color with --ascii_colors is white, it actually leaves the text uncolored, instead using the default foreground color.
https://github.com/dylanaraps/neofetch/blob/ccd5d9f52609bbdcd5d8fa78c4fdb0f12954125f/neofetch#L4725-L4728

I think we have 2 options:

  1. Make a stance that onefetch is preferred on dark terminal themes
  2. Alter the logo colors

@spenserblack
Copy link
Collaborator Author

CI is failing from clippy test unrelated to this PR

@spenserblack spenserblack marked this pull request as ready for review March 17, 2022 18:57
Replaces references to `colored::Color` with `Option<colored::Color>`.

Related to #33
Should improve support for light terminal themes by letting the theme
pick the default text color. Note that white is not always mapped to a
dark color on light themes.

`Token` tests adjusted to not assume white color is the default.

Addresses #33
@spenserblack
Copy link
Collaborator Author

Or I suppose we could just make the Fg variant available (but currently unused), and just fix existing logos as light terminal users point them out.

pub enum OptionalColor {
$( $color, )*
TrueColor{ r: u8, g: u8, b: u8 },
Fg,
Copy link
Owner

@o2sh o2sh Mar 18, 2022

Choose a reason for hiding this comment

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

What about mapping White to None? Like that we don't need to touch the language definitions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that would work (and be more similar to neofetch). Perhaps White and Fg can be effective aliases of each other?

macro_rules! define_optional_color {
($( $color:ident ),*) => {
#[derive(Debug)]
pub enum OptionalColor {
Copy link
Owner

@o2sh o2sh Mar 18, 2022

Choose a reason for hiding this comment

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

I'm not sur about the name, what about AsciiColor instead ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this was back when there was a None variant. AsciiColor sounds good to me.

@o2sh
Copy link
Owner

o2sh commented Mar 18, 2022

You're right, I guess I was just reluctant to add more complexity to the code that would only be beneficial to a small fraction of users. But, what you did is actually pretty clean and as you pointed out neofetch does exactly that.

@spenserblack
Copy link
Collaborator Author

I was just reluctant to add more complexity to the code that would only be beneficial to a small fraction of users

That makes sense. I wouldn't be opposed to delaying any decision on this PR until we get a good idea of how many users really need this (I'm of the opinion that a good light theme would reverse black and white TBH, but it looks like some popular ones don't do that).

By making White ignored as you suggested (#611 (comment)), some complexity could probably be reduced. Perhaps ui::ascii_art::add_colored_segment could use a wrapper type that implements Colorize and ignores White.

owo-colors also looks like it has an interesting way to colorize that could probably greatly reduce complexity, as opposed to needing to rely on colored's (limited) Color enum. I think Default would do what we need. We can make a const called White that aliases Default to reduce diff size and prevent confusion with new contributors.

@o2sh
Copy link
Owner

o2sh commented Mar 18, 2022

owo-colors also looks like it has an interesting way to colorize that could probably greatly reduce complexity, as opposed to needing to rely on colored's (limited) Color enum. I think Default would do what we need. We can make a const called White that aliases Default to reduce diff size and prevent confusion with new contributors.

This is exactly what we need. It will reduce code clutter by removing the need of using Option everywhere.
Let's do it 🚀

@spenserblack
Copy link
Collaborator Author

Let's do it 🚀

Sounds good! I'll leave this PR open for now until the switch to owo-colors is merged. It's unlikely we'll reference commits from this specific PR, but better safe than sorry 🙂

@o2sh o2sh closed this in 7b89eff Mar 22, 2022
@spenserblack spenserblack deleted the feature/none-color branch March 22, 2022 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants