google / comprehensive-rust

This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.
https://google.github.io/comprehensive-rust/
Apache License 2.0
27.84k stars 1.66k forks source link

Colored output in the playground console? #407

Open gendx opened 1 year ago

gendx commented 1 year ago

One selling point of the Rust compiler is colorful error messages that point directly to the problem. However, the embedded playground doesn't illustrate that, because everything becomes monochrome.

While running the course, I occasionally switched to presenting my terminal to illustrate that, but this required some back-and-forth to present a different window, copy-paste the code, run Cargo, etc. This slowed down the course, so I rarely did that.

In principle, there could be a way to take cargo/rustc's colored output, and turn it into suitable HTML/CSS to display the colors in the embedded "console" as well.

mgeisler commented 1 year ago

Yes, I would love to have color output in the playground — the output is probably without color because the compiler detects that stdout is not connected to a terminal. A simple CARGO_TERM_COLOR=always (or the equivalent for rustc) would probably help here. We would then need to translate the ANSI color codes to HTML, but there are libraries for that.

The issues here is related to https://github.com/integer32llc/rust-playground/issues/879, though that issue seems to be mostly about allowing the programs to output colored text. I created https://github.com/integer32llc/rust-playground/issues/900 upstream to track the issue of keeping colors in the compiler error messages.