Skip to content

Fix --no-color not working #14229

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

Merged
merged 1 commit into from
Jan 26, 2025
Merged

Fix --no-color not working #14229

merged 1 commit into from
Jan 26, 2025

Conversation

teatwig
Copy link
Contributor

@teatwig teatwig commented Jan 26, 2025

I wanted to try out the new --color/--no-color options in Elixir 1.18.2 and disabling color doesn't work.

If I create the following file test.exs

IO.puts(IO.ANSI.format([:bright, "test message", :reset]))

and run it from my color enabled terminal it correctly displays in bright text.

If I run it with elixir --no-color test.exs it still prints it with bright text.

After applying the patch in this PR it prints correctly without any ANSI color escape sequences.

image

This seems to be an error when the changes introduced in 786f3ce where refectored: 2c1a836#diff-78a6fd95d2c5f4d0c0a5414b1393fc082ac242d2f70a665abe06f5e571da557d

@teatwig
Copy link
Contributor Author

teatwig commented Jan 26, 2025

I was thinking about adding some tests to lib/elixir/test/elixir/kernel/cli_test.exs but I wasn't sure if it'd make more sense to create a new module for testing ANSI format or to add a test to one of the existing ones.

@josevalim
Copy link
Member

Yes, that was a silly mistake. Thank you for the fix.

Regarding tests, those are hard to test in practice when shelling out, exactly the --no-color, because the default when shelling out is --no-color. :( And on the other cases, the computer may not have ansi enabled.

@josevalim josevalim merged commit a43741f into elixir-lang:main Jan 26, 2025
9 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@teatwig
Copy link
Contributor Author

teatwig commented Jan 26, 2025

Yeah that makes sense.
My idea would've been to simply test the output of evaluating IO.ANSI.enabled?/0 or alternatively inspecting the text to assert whether it has any escape sequences in it.

Something like elixir --color --eval 'IO.puts(IO.ANSI.enabled?())' should always return true.

But it's probably not super necessary :D

@josevalim
Copy link
Member

Yeah, that would work for --color but it wouldn't test --no-color unfortunately as it would be false anyways! :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants