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

Add support for opting out of ANSI coloring via NO_COLOR env. variable #2975

Closed
augustoproiete opened this issue Dec 7, 2020 · 5 comments · Fixed by #2998
Closed

Add support for opting out of ANSI coloring via NO_COLOR env. variable #2975

augustoproiete opened this issue Dec 7, 2020 · 5 comments · Fixed by #2998
Assignees
Projects
Milestone

Comments

@augustoproiete
Copy link
Member

Cake is able to detect if ANSI coloring is supported in a number of cases, but once it detects that color is supported, there's no way of opting out of it at the moment.

Some ideas:

  • Check for the existence of an environment variable (NO_COLOR seems to be a standard) to opt out of ANSI coloring
  • Add a new command-line switch e.g. --no-color and/or --color=false to opt out of ANSI coloring

Common options used to determine if ANSI coloring should be disabled used by some apps on GitHub:

  • Command-line arguments:

    • --no-color
    • --no-colors
    • --color=false
    • --color=never
  • Environment variables:

    • TERM=dumb
    • FORCE_COLOR=false
    • FORCE_COLOR=0
@pascalberger
Copy link
Member

Configuration should IMHO be possible as other configuration options through environment variable, configuration file and argument.

@patriksvensson Is this something which should be done in Spectre.CLI?

@patriksvensson
Copy link
Member

@pascalberger Makes sense to respect NO_COLOR since that's a pretty common convention. Other than that, the rest could be done in Cake.

@augustoproiete
Copy link
Member Author

augustoproiete commented Dec 10, 2020

Sounds good.

For the configuration options, I suggest adding a new configuration value under Settings called Color, which can be one of the following values:

  • auto - Let AnsiDetector decide if color is supported or not based on environment (default)
  • never - opt out of coloring, regardless of environment (skip the logic to detect if color is supported or not)
  • always - opt in on coloring, regardless of environment (skip the logic to detect if color is supported or not)

The color option would be available as ...

  • An argument passed into Cake: --settings_color <value>
  • A configuration file value: Color=value (under the Settings section)
  • An environment variable: CAKE_SETTINGS_COLOR=value

... and follow the same priority order as other configuration values.


As for NO_COLOR I'm thinking this would be an exception to the prioritization rule for environment variables, in the sense that it overrides the Color setting even if defined in the configuration file or passed in as a command-line argument. What do you guys think?

augustoproiete added a commit to augustoproiete-forks/cake-build--cake that referenced this issue Dec 13, 2020
augustoproiete added a commit to augustoproiete-forks/cake-build--cake that referenced this issue Dec 13, 2020
patriksvensson added a commit that referenced this issue Dec 22, 2020
…loring-with-no_color-env-variable

GH-2975: Prevents the addition of ANSI color if NO_COLOR env. variable is present
@pascalberger pascalberger added this to the v1.1.0 milestone Dec 22, 2020
@pascalberger pascalberger added this to To do in 1.x Next via automation Dec 28, 2020
@pascalberger pascalberger moved this from To do to In progress in 1.x Next Dec 28, 2020
@augustoproiete augustoproiete modified the milestones: v1.x Next, v1.1.0 Feb 13, 2021
@augustoproiete augustoproiete changed the title Add support for opting out of ANSI coloring Add support for opting out of ANSI coloring via NO_COLOR env. variable Feb 13, 2021
@augustoproiete
Copy link
Member Author

The scope of this issue was reduced to the NO_COLOR env. variable which was implemented via #2998 and will be released with Cake v1.1.0.

The second part (command-line switch & config optipn) is being tracked via #3138 for a future release

@cake-build-bot
Copy link

🎉 This issue has been resolved in version v1.1.0 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants