-
Notifications
You must be signed in to change notification settings - Fork 122
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
No color output when run via Gradle's run
task (or Docker)
#428
Comments
Yes, this is because Mordant is disabling color when output is redirected (see ajalt/mordant#104). Unfortunately, there's no way to know if you're redirected to a file or a pipe that will end up in the screen eventually, so I choose to disable colors to avoid ANSI codes ending up in a file. Most other colored terminal programs do the same. As mentioned in the linked issue, you can force color with |
Yeah, that's also the conclusion people I've asked came up with in this Gradle Slack thread. Just wondering, with clikt using Mordant now, would it make sense to by default provide |
That's a good idea. I know some popular CLIs have a Mordant supports all the popular environment variables ( |
Ok. Users who still want |
However, if I try to do
and
I'm running into Also, I'd like a PS: I'd prefer to not use environment variables to not affect other processes than my own. |
You cannot read from an option in But for the same reason i mentioned above, it won't work if you call You can set environment variables for a single process, e.g. from the command line |
For reference, I'm now solving this on a Gradle task level: tasks.named<JavaExec>("run") {
System.getenv("TERM")?.also {
val mode = it.substringAfter('-', "16color")
environment("FORCE_COLOR" to mode)
}
System.getenv("COLORTERM")?.also {
environment("FORCE_COLOR" to it)
}
} |
This can be reproduced with samples/helpformat:
shows colored help:
But
does not:
I guess this happens because Gradle redirects the output and thus some terminal detection (probably rather in Mordant than in clikt) fails.
A similar thing happens when "dockerizing" apps and (in this case) using the
build/install/helpformat/bin/helpformat
script as the entry point. Then something likedocker run helpformat --help
also shows no color.I'm not sure whether this even can be fixed reliable without making hacky assumptions, but I wanted to bring it up.
The text was updated successfully, but these errors were encountered: