Improve support for light background terminals.
Review Request #13505 — Created Jan. 21, 2024 and submitted — Latest diff uploaded
macOS's terminals default to a white background, but don't convey that
fact in any environment variables. However, it does support the ANSI
escape sequence used to fetch the color palette.We now fall back to invoking this ANSI escape sequence, attempting to
fetch the background color. This comes back as a XParseColor value in
the form of11;rgb:RRRR/GGGG/BBBB
, where the red/green/blue are values
between 1 and 4 characters in length, as hex values representing a
fraction of the color in the available color depth.These are converted back to traditional RGB values between 0-255. We
then calculate a luma value from this, and use that to determine if we
want to show dark vs. light colors. This ends up working fairly well for
most any realistic color palette, and has been tested across all kinds
of backgrounds.The header text has also been changed to work better on many lighter
color backgrounds. Rather than reverse text, we now use an explicit
black on green, which should be stable across all "light" backgrounds.
Tested this across a wide range of backgrounds. I tested white, black,
a spectrum of shades of grey, various blues, reds, yellows, greens, and
some combinations of those.Tested without a TTY.
Tested this on macOS (Apple Terminal and iTerm) and Linux terminals.