Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

NO_COLOR support #99

Open
msalib opened this issue Feb 4, 2022 · 3 comments
Open

NO_COLOR support #99

msalib opened this issue Feb 4, 2022 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@msalib
Copy link

msalib commented Feb 4, 2022

I love color-eyre when developing locally; it is so incredibly helpful! But the colors are a problem when deploying to prod where, for example, Cloudwatch logs for AWS Lambda functions just include raw ANSI escape sequences. I'm working around that right now by using this code in my setup function:

        if std::env::var("NO_COLOR") == Err(std::env::VarError::NotPresent) {
            color_eyre::install()?;
        } else {
            color_eyre::config::HookBuilder::new()
                .theme(color_eyre::config::Theme::new())
                .install()?;
        }

and making sure our prod deployments include NO_COLOR=1.

I'd love to see either:

  • a mention of this particular pattern in the docs (I searched and couldn't find anything), or
  • a change to HookBuilder::blank() selecting either the default dark theme or the blank theme based on the presence of NO_COLOR

I'm sure you've already seen this, but I found https://no-color.org/ helpful

I'm sorry I don't have the time right now to write up a draft PR for you.

@yaahc
Copy link
Collaborator

yaahc commented Feb 4, 2022

Glad to hear you're enjoying color-eyre 😊.

a mention of this particular pattern in the docs (I searched and couldn't find anything)

Happy to add this. Do you remember where you searched for this first? I figure those will be the best places to put the example to make sure ppl find it in the future.

a change to HookBuilder::blank() selecting either the default dark theme or the blank theme based on the presence of NO_COLOR

Also happy with doing this, I think I have a preference for the former suggestion but I don't mind this one or even doing both.

I'm sure you've already seen this, but I found https://no-color.org/ helpful

I hadn't seen this! I think this would be a good link to include in any updated examples we end up adding for this.

I'm sorry I don't have the time right now to write up a draft PR for you.

No worries! Thank you for taking the time to submit the issue.

@yaahc yaahc added good first issue Good for newcomers help wanted Extra attention is needed documentation Improvements or additions to documentation enhancement New feature or request labels Feb 4, 2022
@pksunkara
Copy link
Contributor

There was quite a bit of work done on colorchoice crate as part of https://github.com/rust-cli/anstyle that handles the "should we color?" question. cc @epage

@epage
Copy link

epage commented Jul 26, 2023

colorchoice is just about having a central global so CLI control doesn't need to be piped through the entire program.

For NO_COLOR, that would normally be handled via printing via anstream which has you write your colors and then strips them depending on the environment the program is running within

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants