powerline-shell icon indicating copy to clipboard operation
powerline-shell copied to clipboard

Adding TrueColor/RGB support to themes

Open typedef-sorbet opened this issue 5 years ago • 0 comments

I've added TrueColor support to the color system, to allow for themes to be more flexible in their color usage rather than being limited to only xterm-256 color space.

The Powerline ctor now checks for TrueColor support by checking the COLORTERM environment variable, and sets a flag.

The color() function in powerline_shell/__init__.py both checks this flag, as well as the type of the color information coming in from the theme. If the color is an integer, it is applied as an xterm-256 color as normal. If the color is an RGB tuple, however, one of two things happens:

  • If the terminal does support TrueColor, the color is applied using an alternative color coding string
  • If the terminal does not support TrueColor, the color is converted to the closest xterm-256 color using colortrans.rgb2short before being applied.

Color fallback works as normal if a theme doesn't specify a color for a certain segment property.

I've also added a color test script specifically for TrueColor, however it only allows for testing one background and foreground color each, since interpolating between two RGB values for each would be intensive, and likely not fit cleanly on a user's terminal.

typedef-sorbet avatar Feb 16 '21 03:02 typedef-sorbet