-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
ANSI colors not closed on cargo test
#1198
Comments
Does this reproduce reliably for you? I suspect that this may be because there are two compilations occurring in parallel. If you run |
I've ran into similar issues with colors using the windows console and using |
I was running I'm on Win 8.1 x64.
|
Has anyone seen duplication happen at color change boundaries? $ cargo -V |
Yeah this'll happen because Cargo is running two instances of the compiler in parallel and they're both producing error messages. The ANSI codes don't play well when emitted concurrently, causing weird coloration and/or interleaving. |
Random idea to try to fix this, if it is indeed caused by parallel rustc’s writing to the same terminal unsynchronized:
|
I think that may work for Unix, but unfortunately I don't think it'd work for Windows. The colorization I think is a global state of the terminal itself rather than an encoded part of the output stream (yay!). Not to say that it shouldn't be done, but it unfortunately wouldn't close the issue :( |
Color is not a state of the console, but rather the console buffer. You can create multiple console buffers, although only one is displayed at a time. You can pass one of these background console buffers to the spawned rustc, and when its done, write that output to the primary buffer. |
An alternative cross platform way is to have rustc output warnings and errors in a machine readable format and then have Cargo responsible for formatting the errors and warnings in a human readable format with colors. |
I've opened rust-lang/rust#32486 after discussing with @brson which would hopefully provide a nice way to mitigate this in the meantime. |
I'd like to recommend a more complete approach to solving this, and other inter-mixed output issues Buffer all output from a command, when run in parallel, before displaying it. This is the approach another build tool (ninja-build takes, and it has the added benefit of allowing cargo to make absolutely clear to the user which output is associated with which command (ie: it can print the command invocation above the output when a warning or error occurs). |
@jmesmon The only problem with that is you'd need to be really clever to make it preserve colors with the Windows console which uses API calls instead of ansi escape codes. As I mentioned above we could either spawn new console buffers for each process and then copy out the output, or we could have rustc emit a machine readable format and then cargo can add colors to that when printing it out. |
I believe this has since been fixed in the compiler, so closing. |
Ran into a build failure during cargo test. The red color in the terminal didn't terminate, leaving me a red terminal and an empty feeling in my soul.
The text was updated successfully, but these errors were encountered: