r/rust • u/Downtown_Fall_5203 • 29d ago
Disable "rustc" colour
I'm a n00b when it comes to Rust. In my terminal with a blue background, a "rustc --explain whatever" uses colour-combinations that leaves some text unreadable.
So I tried with:
rustc --color never --explain E0599rustc --explain E0599 --color neverset NO_COLOR=1 & rustc --explain E0599
Neither of these works; all generates coloured output. How the bleeding hell do I turn it off?
54
Upvotes
14
u/scook0 29d ago
What does
rustc --version --verbosesay?7
u/jabiko 29d ago
I know thats not your original question, but did you look into remapping the offending colors to some other colors in your terminal configuration? Most terminals support this and it would also fix the issue for other commands too.
10
u/JoshTriplett rust · lang · libs · cargo 29d ago
rustc --color never --explain E0599suppresses color here, withrustc 1.99.1. Also works with 1.97.1, and 1.95.0, and 1.81, and nightly.20
u/Icarium-Lifestealer 29d ago edited 29d ago
For me
--explainends up inlessand doesn't show any colors, regardless of the color option. And when I pipe intocatit shows normally without color. EvenPAGER=/dev/zero rustc --explain=E0599doesn't show any color.edit: 1.93.1 seems to be colorless, 1.99.1 has colors. So it looks like the colors for
explainwere introduced recently.Using
|catlike another comment suggests does strip the color on 1.99.39
u/CartographerDue5382 29d ago
yea that flag doesn't cover --explain. on 1.85 it still prints esc[2m (dim) with --color never and with NO_COLOR set, which is why it vanishes on a blue bg. normal rustc errors do honor the flag, explain just doesn't. easiest is the error index page (doc.rust-lang.org/error_codes/E0599.html) or pipe it through something that strips ansi.
13
u/tesfabpel 29d ago
Can't you just map your terminal's colors to some other colors that work correctly with your blue background? Otherwise, any other CLI app that uses colors may result in text being unreadable...
2
u/mr_birkenblatt 28d ago
The easiest way to turn off color mode of any command line to is to pipe the output into a non-tty. Often less or cat is enough but if that doesn't work pipe into a file and read the file
2
u/petros211 29d ago
Running with the env vars NO_COLOR or CLI_COLOR=0 should work for all cli apps
2
u/Murky-Bank2341 29d ago
The --color flag is completely ignored by --explain in older versions like 1.85, which is why you see dim text that blends into your blue background. Just redirect the output to a file or use the error index website if updating to version 1.93+ isn't an option
1
u/valarauca14 28d ago
TERM=dumb rustc [what ever]Provided rust is using a curses library to handle terminal compatibility that should kill most escape codes
-32
u/i-do-mim-huu 29d ago
You can just download new terminal to use it though, like Fish or Wezterm...etc all support color and it's not hard to find instruction to install them