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

Don't remove color information from rendered string in --message-format=json output #6994

Closed
mchernyavsky opened this issue May 29, 2019 · 2 comments
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@mchernyavsky
Copy link
Contributor

Describe the problem you are trying to solve

I'm trying to support new build tool window for IntelliJ Rust:

image

I use --message-format=json option, but unfortunately the rendered string doesn't contain color information.

Describe the solution you'd like

I would like to use --color=always option (or some new one) to include color information.

Notes
I think this is the place where it can be fixed:

// Remove color information from the rendered string. rustc has not
// included color in the past, so to avoid breaking anything, strip it
// out when --json-rendered=termcolor is used. This runs
// unconditionally under the assumption that Cargo will eventually
// move to this as the default mode. Perhaps in the future, cargo
// could allow the user to enable/disable color (such as with a
// `--json-rendered` or `--color` or `--message-format` flag).
#[derive(serde::Deserialize, serde::Serialize)]
struct CompilerMessage {
rendered: String,
#[serde(flatten)]
other: std::collections::BTreeMap<String, serde_json::Value>,
}
if let Ok(mut error) = serde_json::from_str::<CompilerMessage>(compiler_message.get()) {
error.rendered = strip_ansi_escapes::strip(&error.rendered)
.map(|v| String::from_utf8(v).expect("utf8"))
.unwrap_or(error.rendered);

@mchernyavsky mchernyavsky added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label May 29, 2019
@ehuss ehuss added the A-diagnostics Area: Error and warning messages generated by Cargo itself. label Jun 24, 2019
@ehuss
Copy link
Contributor

ehuss commented Jun 24, 2019

This is gated on rust-lang/rust#60987

bors bot added a commit to intellij-rust/intellij-rust that referenced this issue Aug 12, 2019
3926: RUN: Support build tool window r=ortem a=mchernyavsky

Closes #2638. Fixes #3777. Fixes #3843.

![toolwindow](https://user-images.githubusercontent.com/6079006/60440179-efefd380-9c1c-11e9-9ea3-4c319552694c.gif)

Overview:
- TODO

rust-lang/cargo#6994

Co-authored-by: mchernyavsky <mikhail.chernyavsky@jetbrains.com>
Co-authored-by: Mikhail Chernyavsky <mikhail.chernyavsky@jetbrains.com>
@mchernyavsky
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants