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

Make colorizer respect AppSettings::ColorAlways / ColorChoice::Always #2651

Merged
merged 1 commit into from
Aug 1, 2021
Merged

Conversation

abysssol
Copy link

@abysssol abysssol commented Jul 31, 2021

AppSettings::ColorAlways currently appears to have no effect.
This was an issue in the past (see #1400), but was fixed in pr #1402; however, it seems to have been broken again.

I have tested the altered colorizer in a local project, and it seems to have the correct behavior.
No lints are triggered. All tests have passed.

This should fix issue #1400 ... again.

Copy link
Member

@epage epage left a comment

Choose a reason for hiding this comment

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

I did some digging and it looks like #1402 was lost when transitioning from v2 to v3. The commit shows up in v2-masters history but not in masters.

I feel like colored support in the rust ecosystem lends itself to these kinds of problems. I'm working on an exploration of it to better understand what might help make things better.

@abysssol
Copy link
Author

abysssol commented Aug 1, 2021

I don't have much experience in the matter, but the colored crate (which I have used recently) seems to provide a user-friendly api. By default, it automatically detects whether the output is to a terminal or pipe, and disables color accordingly. It also has functions to force colored output, or force no color (using static variables).
I'm not sure if it would be insufficient for this project somehow, but it seems like it would make this type of problem far less likely, since it already handles most of the coloring logic.
Of course, at this point in development it would be more trouble than it's worth to port to it from termcolor, but it seems to me that it would make errors of this type in any projects that use it a non-issue (thus fixing color support in the rust ecosystem).
Again, I don't have much experience, so if I'm wrong, and there are some other important factors that I don't know about, please let me know, I'd love to learn more.

@epage
Copy link
Member

epage commented Aug 1, 2021

I don't have much experience in the matter, but the colored crate (which I have used recently) seems to provide a user-friendly api. By default, it automatically detects whether the output is to a terminal or pipe, and disables color accordingly. It also has functions to force colored output, or force no color (using static variables).
I'm not sure if it would be insufficient for this project somehow, but it seems like it would make this type of problem far less likely, since it already handles most of the coloring logic.
Of course, at this point in development it would be more trouble than it's worth to port to it from termcolor, but it seems to me that it would make errors of this type in any projects that use it a non-issue (thus fixing color support in the rust ecosystem).
Again, I don't have much experience, so if I'm wrong, and there are some other important factors that I don't know about, please let me know, I'd love to learn more.

My interest isn't in any particular styling crate (there are a lot of different API trade offs) but in providing the tooling to ensure the user and the styling crates provide a good experience.

For example, while colored does a lot of things right, it only does tty detection on stdout and applies that to both stdout and stderr.

On another level of the problem, as an end user of clap and env_logger, you have to know the implementation details of the styling libraries to know when to override them yourselv because their logic is incomplete.

Like I said, its a mess which is why I'm looking into it. I'll have something posted to the rust-cli org soon-ish.

@pksunkara pksunkara merged commit 25f6958 into clap-rs:master Aug 1, 2021
@epage
Copy link
Member

epage commented Aug 2, 2021

@AbyssAbuse see rust-cli/team#15 (comment)

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.

3 participants