[Toybox] Question about --color

Rob Landley rob at landley.net
Sat Aug 13 03:50:12 PDT 2022


On 8/10/22 10:02, enh wrote:
> i don't have a _technical_ reason, but i will say i've always hated `ls --color`
> and the first thing i do on a new OS install is _delete_ those default aliases.
> 
> (actually, trying to translate that into a technical reason: you can't ask
> terminals what the rgb value for an ansi color is,

Do you know about the new 24-bit color escape sequences? I played with them a
bit last year:

  https://landley.net/notes-2021.html#06-10-2021

It's printf("\e[38;2;%d;%d;%dm", red, green, blue); to set the foreground color
(each is 0-255), and 48;2 instead of 38;2 to set the background color.

> and you can't even ask
> whether there's a dark-on-light or light-on-dark scheme, so you can't really
> guarantee that your default colors are at all visible. see also: accessibility
> issues for people with various kinds of color vision deficiencies.)

Part of my new install checklist is xfce terminal edit->preferences->colors to
make the background be ACTUALLY BLACK (rather than just dark grey) and bump up
their idea of "dark blue" a little bit so it's legible.

There's an LS_COLORS environment variable, but that's the standard gnu failure
mode of playing whack-a-mole on each command instead of having global consistent
behavior. (We talked about that.)

> since i don't have any issues with red or green on a dark background in any
> terminal i've used,

Except the most common kind of colorblindness is red/green. :)

They have colorblind correction glasses these days, but they're still under
patent so they're many hundred of dollars per pair. Entrapta, Encarta... ah:

https://www.youtube.com/watch?v=WCcxwieuDH0

> i don't actually mind `diff --color` and whenever a new git
> install asks me whether i can see the diff i just choose "yeah, whatever". it's
> blue/magenta on dark or yellow/green on light that i find problematic. (what rgb
> values "yellow" actually comes out as varies the most widely between terminals
> of any color.)

In theory there's some environment variable that can provide a color mapping to
override the defaults. In practice, the existence of the "dircolors" command is
Peak Gnu. It ONLY sets the colors for ls, not any other command. I.E. their ls
implementation has a whole supporting command to set an environment variable for it.

As an aside, the "apropos" command is meta-annoying because neither "apropos
color" nor "apropos colors" mentions ls (it's not searching the CONTENTS of the
man page, just some decription field), and the meta part is that apropos --help
does not actually have a description line saying what the command DOES.

"zgrep -wl color /usr/share/man/man1/*.gz" worked though: looks like ls, top,
grep, diff, and dmesg in toybox so far. (Plus less -R and watch -c but that's
not an a decision about WHICH colors to output.) The troff man page says it has
an option to _disable_ color output, but what does it do with color when it's
not disabled?)

I note that in dmesg you already enabled color with no --color to switch it on
and no obvious way to switch it off except piping it through cat, so my current
pondering on this topic has precedent. I may not know what's "right" but I tend
to want the behavior to be CONSISTENT (and if at all possible have a common
implementation), and right now it's not...

Rob


More information about the Toybox mailing list