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

Console launcher should support NO_COLOR environment variable #3328

Closed
sormuras opened this issue May 28, 2023 · 9 comments · Fixed by #3948
Closed

Console launcher should support NO_COLOR environment variable #3328

sormuras opened this issue May 28, 2023 · 9 comments · Fixed by #3948

Comments

@sormuras
Copy link
Member

Support NO_COLOR environment variable as described by https://no-color.org in JUnit's console launcher.

@marcphilipp
Copy link
Member

Team decision: Check if picocli supports this already and, if not, raise an issue.

@sormuras
Copy link
Member Author

sormuras commented Jun 7, 2023

Seems to be the case: https://picocli.info/#_heuristics_for_enabling_ansi

@marcphilipp
Copy link
Member

Team decision: Check if our Console Launcher already supports this or what would need to be done in order to do so.

@marcphilipp marcphilipp added this to the 5.11 M1 milestone Jun 7, 2023
@marcphilipp marcphilipp modified the milestones: 5.11 M1, 5.12 Feb 2, 2024
@marcphilipp marcphilipp modified the milestones: 5.11 M2, 5.11 M3 May 17, 2024
@sormuras
Copy link
Member Author

sormuras commented Jul 8, 2024

  • $ java -jar junit-platform-console-standalone-1.10.3.jar engines

💚 Thanks for using JUnit! Support its development at https://junit.org/sponsoring

junit-jupiter (org.junit.jupiter:junit-jupiter-engine:5.10.3)
junit-platform-suite (org.junit.platform:junit-platform-suite-engine:1.10.3)
junit-vintage (org.junit.vintage:junit-vintage-engine:5.10.3)

  • $ export NO_COLOR=1
  • $ java -jar junit-platform-console-standalone-1.10.3.jar engines
Thanks for using JUnit! Support its development at https://junit.org/sponsoring

junit-jupiter (org.junit.jupiter:junit-jupiter-engine:5.10.3)
junit-platform-suite (org.junit.platform:junit-platform-suite-engine:1.10.3)
junit-vintage (org.junit.vintage:junit-vintage-engine:5.10.3)

The console launcher already does support NO_COLOR.

@sormuras sormuras closed this as completed Jul 8, 2024
@sbrannen
Copy link
Member

sbrannen commented Jul 8, 2024

The console launcher already does support NO_COLOR.

Cool! 👏

In light of that, I'm removing this from the 5.11 RC1 milestone.

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
@sbrannen sbrannen removed this from the 5.11 RC1 milestone Jul 8, 2024
@dhoard
Copy link

dhoard commented Sep 8, 2024

Based on my testing using 5.11, the NO_COLOR environment variable is not fully supported.

Shell

> export NO_COLOR=1
> export | grep NO_COLOR
declare -x NO_COLOR="1"
> java -cp "junit-platform-console-standalone-1.11.0.jar:tests/target/test-classes:tests/lib/*" org.junit.platform.console.ConsoleLauncher execute --scan-classpath -n "JUnit5"

Output

image

Code

Looking at the code, only the --disable-ansi-colors command line option is used to determine whether to use ANSI colors. If I use the command line option, ANSI colors are disabled.

@Option(names = "--disable-ansi-colors", description = "Disable ANSI colors in output (not supported by all terminals).")
public void setDisableAnsiColors(boolean disableAnsiColors) {
if (disableAnsiColors) {
commandSpec.commandLine().setColorScheme(defaultColorScheme(Ansi.OFF));
}
this.disableAnsiColors = disableAnsiColors;

@sormuras
Copy link
Member Author

sormuras commented Sep 8, 2024

Thanks for reporting this, @dhoard - it's an initialization issue.

should read like: private boolean disableAnsiColors = System.getenv("NO_COLOR") != null; instead of being set to false. It would be even better to tap into PicoCLI's heuristic programmatically.

@sormuras sormuras reopened this Sep 8, 2024
sormuras added a commit that referenced this issue Sep 8, 2024
@sbrannen sbrannen changed the title Console launcher should support NO_COLOR environment variable Console launcher should support NO_COLOR environment variable Sep 8, 2024
@sbrannen sbrannen added this to the 5.11.1 milestone Sep 8, 2024
@marcphilipp marcphilipp linked a pull request Sep 8, 2024 that will close this issue
6 tasks
sormuras added a commit that referenced this issue Sep 9, 2024
sormuras added a commit that referenced this issue Sep 10, 2024
@sbrannen

This comment was marked as outdated.

@sbrannen
Copy link
Member

@sbrannen sbrannen modified the milestones: 5.11.1, 5.12 M1 Sep 13, 2024
marcphilipp pushed a commit that referenced this issue Sep 16, 2024
marcphilipp pushed a commit that referenced this issue Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants