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

Cargo display color codes on terminals (TERM) without color support #11211

Open
amarao opened this issue Oct 11, 2022 · 2 comments
Open

Cargo display color codes on terminals (TERM) without color support #11211

amarao opened this issue Oct 11, 2022 · 2 comments
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

Comments

@amarao
Copy link

amarao commented Oct 11, 2022

Problem

Some terminals lack ability to display colors. If TERM is set to the terminal type without color support, cargo should not put random (other terminal codes) on the screen.

Steps

  1. TERM=t10 cargo build

Expected result: no color codes.
Actual result: color console codes in output.

Possible Solution(s)

Unknown terminal types should switch cargo into 'no colors' mode.

Notes

infocmp t10
#	Reconstructed via infocmp from file: /usr/share/terminfo/t/t10
t10|Teleray 10 special,
	km, xhp, xt,
	cols#80, it#8, lines#24, xmc#2,
	clear=\Ej$<30/>, cub1=^H, cud1=\EB, cuf1=\EC,
	cup=\EY%p1%' '%+%c%p2%' '%+%c, cuu1=\EA, dch1=\EQ,
	dl1=\EM, ed=\EJ, el=\EK, home=\EH, ht=^I, ich1=\EP, il1=\EL,
	ind=\Eq, pad=\0, ri=\Ep, rmso=\ER@, rmul=\ER@, smso=\ERD,
	smul=\ERH,

Version

cargo 1.63.0 (fd9c4297c 2022-07-01)
release: 1.63.0
commit-hash: fd9c4297ccbee36d39e9a79067edab0b614edb5a
commit-date: 2022-07-01
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1n)
os: Ubuntu 22.10 (kinetic) [64-bit]
@amarao amarao added the C-bug Category: bug label Oct 11, 2022
@weihanglo
Copy link
Member

Cargo at this moment depends on termcolor and atty to detect color support. So far as I understand it, rules are:

  1. If atty detects the stream source is a tty, hand over to termcolor to determine.1
    1. if TERM=dumb or NO_COLOR is set, disable the color support. 2
    2. Otherwise enable it.
  2. Otherwise disable the color support.

I am not an expert on tty specifications, but this seems to be more an enhancement of upstreams.

As of now, environment variable CARGO_TERM_COLOR=never is at your service, as well as the configuration counterpart term.color.

Footnotes

  1. https://github.com/rust-lang/cargo/blob/b8f30cb23c4e5f20854a4f683325782b7cff9837/src/cargo/core/shell.rs#L504-L506

  2. https://github.com/BurntSushi/termcolor/tree/1.1.3#automatic-color-selection

@weihanglo weihanglo added A-console-output Area: Terminal output, colors, progress bar, etc. S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix labels Oct 11, 2022
@epage
Copy link
Contributor

epage commented Oct 11, 2022

I'm curious, what is your reason for TERM=t10?

Unknown terminal types should switch cargo into 'no colors' mode.

For some reason most new CLIs seem to be eschewing termcap and running heuristics on TERM. Most I see just check TERM=dumb though supports-color does do a few more checks.

At least when discussing it within the CLI-WG, someone made this statement

Remember that terminfo and termcap came from a time when there were a lot of very weird non-VT-series terminals around, and if you wanted your app to work at all, then you had to use the peculiar sequences required by those terminals. Nowadays it's reasonable to assume basic ANSI support. So, for colour if you just use plain 8-colour ANSI sequences and maybe bold, it shouldn't need any feature testing. So either aim for the lowest common denominator (easy) or try to get fancy and detect extra features (harder). Also bear in mind that the user might be running with either a white or black default background (colour 49). So blue on default-background might be readable on white, but probably won't be on black. This is all UNIX, though -- I don't know the Windows situation.

@epage epage changed the title Cargo display color codes on terminals without color support Cargo display color codes on terminals (TERM) without color support Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix
Projects
None yet
Development

No branches or pull requests

3 participants