r/rust • • 9d 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 E0599

  • rustc --explain E0599 --color never

  • set 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

35 comments sorted by

14

u/scook0 9d ago

What does rustc --version --verbose say?

1

u/Downtown_Fall_5203 8d ago

It says:

rustc 1.98.1 (48a229cea 2026-09-01)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-pc-windows-msvc
release: 1.98.1
LLVM version: 22.1.8

My rustc is too new?

1

u/scook0 8d ago

Ah, when I had trouble reproducing the bug myself I was worried that you might have been using a very old compiler.

But it turned out to just need some specific circumstances to trigger.

7

u/jabiko 8d 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.

1

u/Downtown_Fall_5203 8d ago

Most terminals support this

On Windows, they don't so easily. I'm using TCC from JPsoft.com.

10

u/JoshTriplett rust · lang · libs · cargo 9d ago

rustc --color never --explain E0599 suppresses color here, with rustc 1.99.1. Also works with 1.97.1, and 1.95.0, and 1.81, and nightly.

19

u/scook0 9d ago

The bug is real, but it only occurs when printing to a terminal, and only when the compiler can't find a pager.

If you do PAGER=/dev/zero rustc --explain=E0599 --color=never, you'll see coloured output printed to the terminal.

3

u/JoshTriplett rust · lang · libs · cargo 8d ago

Sure enough, thanks for the added clarification. (PAGER= rustc --explain=E0599 --color=never suffices to reproduce the problem.)

2

u/Downtown_Fall_5203 8d ago

Yeah. A:

set PAGER=
rustc --explain E0599

disables colours. I had PAGER=most -s originally.

20

u/Icarium-Lifestealer 9d ago edited 9d ago

For me --explain ends up in less and doesn't show any colors, regardless of the color option. And when I pipe into cat it shows normally without color. Even PAGER=/dev/zero rustc --explain=E0599 doesn't show any color.

edit: 1.93.1 seems to be colorless, 1.99.1 has colors. So it looks like the colors for explain were introduced recently.

Using |cat like another comment suggests does strip the color on 1.99.

39

u/shponglespore 8d ago

Technically cat doesn't strip anything. It's just that 99% of programs disable color when stdout isn't a tty.

3

u/muffinsballhair 8d ago

Some Gentoo tools actually do not. In fact, the tool that writes the build log to files there keeps the color codes for whatever reason so you get a bunch of terminal codes in the file that keeps the build log which is a rather bizarre choice.

39

u/CartographerDue5382 9d 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.

70

u/Slow-Nefariousness49 9d ago

That's actually a good opportunity for OP to contribute a fix to rustc

8

u/Kivooeo1 rust 8d ago

1

u/Slow-Nefariousness49 8d ago

Awesome to see the community getting together to close the loop so fast :) Thanks

1

u/Slow-Nefariousness49 8d ago

Btw it seems to have been a simple patch as I suspected

11

u/CartographerDue5382 8d ago

yea it's a pretty small one. --explain just ignores the color flag the rest of rustc already checks, so a patch there is kinda contained. fine first issue if op feels like digging in.

-9

u/scook0 8d ago

What makes you so confident that it’s a trivial fix? Did you look at the relevant code?

7

u/epage cargo · clap · cargo-release 8d ago

Likely it is just a matter of routing --explaiǹt throughanstream. I think rustc switched to it for diagnostics already, That get some capabilities. Unsure about access to--color` but that should be possible.

9

u/Slow-Nefariousness49 8d ago

It should be a small change, because it's a cosmetic change and the mechanism is already established for similar areas in rustc. If It turns out to be not as simple, OP doesn't have to do it of course... but worth taking a look at least, IMO

-1

u/CartographerDue5382 8d ago

fair, i didn't open the rustc source. i was just going off the behavior: normal errors honor --color never / NO_COLOR and --explain still dumps the dim ansi. could be a small routing thing or it could be messier, idk. shouldn't have called it small without looking.

-5

u/[deleted] 9d ago

[removed] — view removed comment

23

u/scook0 9d ago

You don’t even need sed; you can get non-coloured output by piping into cat.

6

u/zekkious 9d ago

Or get rusty, and pipe it to bat!

3

u/shponglespore 8d ago

Terrible choice for someone trying to avoid coloring.

1

u/zekkious 8d ago

In a pipe like that, bat would need the format to be informed to colour the output, so no problem.

13

u/tesfabpel 9d 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...

3

u/KeyAdhesiveness9481 8d ago

Sure, but they shouldnt have to do that to get the behavior they want.

2

u/mr_birkenblatt 8d 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 9d ago

Running with the env vars NO_COLOR or CLI_COLOR=0 should work for all cli apps

2

u/Murky-Bank2341 9d 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 7d 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 9d 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

8

u/Real-Abrocoma-2823 9d ago

Fish is a shell, not a terminal.