Improve support for light background terminals.

Review Request #13505 — Created Jan. 21, 2024 and submitted

Information

rbinstall
master

Reviewers

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 of 11;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
Improve support for light background terminals.
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 of `11;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.
9041130fe767daef394784552da91d1c28f76f2b
Description From Last Updated

Missing a "Returns" section in the docs.

maubinmaubin
maubin
  1. 
      
  2. rbinstall/ui.py (Diff revision 1)
     
     
    Show all issues

    Missing a "Returns" section in the docs.

  3. 
      
chipx86
maubin
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to master (2e96273)
Loading...