-
Notifications
You must be signed in to change notification settings - Fork 218
Don't print colors when ANSI codes are not supported #19
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
Comments
This is very difficult in full generality. The best way to detect this is to use What we should do in the short term is support a |
Why does it work in pub? When I run it in a shell which supports ANSI codes it's colored otherwise it's without color but also doesn't print the ANSI codes. |
Pub isn't run inside pub 😉. It's possible for Dart programs to detect whether it's safe to use colors using |
I see. Thanks for the explanation! |
If I run my test file without the test runner from Dart Editor I would also not expect it to use ANSI codes (at least on Windows). As this doesn't run via pub run, shouldn't it possible to use stdioType here? |
@Fox32 There's no way of telling whether we're running via |
I haven't found a way to pass |
That's correct. Unfortunately, there's no global way to access command-line flags (issue 22466), so the In general, you should think of running a script directly as a handy shortcut when working from the terminal. There are a lot of things it won't be able to support: not just colors, but configurations, annotations, and so forth. The official way to run a test is via |
This is inconvenient during development because this way debugging isn't supported. There is an open issue about debugging but I have no idea how this could work with pub run. |
Issue 21791 will allow us to spin up test isolates with debugging ports open. For now, though, debugging is not officially supported; you're welcome to use it with |
Good to know |
You should be able to just look at the TERM environment variable to determine the current state of the console. |
Accurately parsing |
It's the way e.g. I don't see how anything else is going to work. How could e.g. a build script know to pass --no-color? Someone at some point is going to have to examine the terminal capabilities, since not everyone is going to be running the build scripts in the same environment. Asking everyone to write build scripts that check the terminal state to know whether to pass --no-color or not is a non-starter, IMHO. |
As this comment mentions, the plan is to use |
Closing: Working as intended. |
This is how the output looks like in WebStorm debug console:
Other packages run into this as well.
pub
itself is one of these where it works well.see also
The text was updated successfully, but these errors were encountered: