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

feat: dynamic colors #86

Merged
merged 7 commits into from
Nov 10, 2022
Merged

feat: dynamic colors #86

merged 7 commits into from
Nov 10, 2022

Conversation

miraclx
Copy link
Contributor

@miraclx miraclx commented Nov 4, 2022

Observed a weird behavior where cargo-near disables colors when stdout is piped, even though we're printing to stderr.

Looked into the logic of the dependency colored, and it's pretty rigidly tied to stdout. But thankfully, you can override it.

The logic implemented here is in two parts.

  1. The NO_COLOR env. https://no-color.org/. colored also uses this internally.
  2. The --color <auto|always|never> which takes precedence over the env.

This configuration also applies to the cargo subprocesses.

@miraclx miraclx requested a review from itegulov November 4, 2022 02:40
@miraclx miraclx requested a review from austinabell November 4, 2022 02:50
@miraclx
Copy link
Contributor Author

miraclx commented Nov 4, 2022

Alternatively, we can switch from colored to something like console that lets you enable/disable colors depending on what tty you're writing to.

https://docs.rs/console/latest/console/struct.Style.html#method.for_stderr

Although the syntax would look a bit like eprintln!("{}", style("hello").for_stderr().cyan())

Copy link
Contributor

@austinabell austinabell left a comment

Choose a reason for hiding this comment

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

change seems reasonable!

@miraclx miraclx mentioned this pull request Nov 10, 2022
@miraclx miraclx merged commit 4082d58 into main Nov 10, 2022
@miraclx miraclx deleted the miraclx/dyn-color branch November 10, 2022 03:19
@miraclx miraclx linked an issue Nov 10, 2022 that may be closed by this pull request
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.

Add ability to control colorized output
2 participants