near / cargo-near

Cargo extension for building Rust smart contracts on NEAR
Apache License 2.0
34 stars 17 forks source link

feat: dynamic colors #86

Closed miraclx closed 1 year ago

miraclx commented 2 years ago

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 commented 2 years ago

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())