Improve support for light background terminals.
Review Request #13505 — Created Jan. 21, 2024 and submitted
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.
Summary | ID |
---|---|
9041130fe767daef394784552da91d1c28f76f2b |
Description | From | Last Updated |
---|---|---|
Missing a "Returns" section in the docs. |
maubin |
- Change Summary:
-
Added a missing "Returns" section in
query_terminal()
. - Commits:
-
Summary ID a215d75e313b80b0867d1624ba3a09ccb3d822a2 9041130fe767daef394784552da91d1c28f76f2b - Diff:
-
Revision 2 (+224 -8)