Allow customizing the extended color palette from config #489

Closed
opened 6 months ago by novenary · 6 comments

I like to make my color schemes compatible with base16.

This is a 16 color palette, but using the 8 bright colors for the extra colors tends to make some programs look terrible. Setting bold-text-in-bright=no is not enough, because some applications use SGR 38/48 and still expect colors 8-15 to be consistent with colors 0-7.
On the other hand, very few programs make use of the 88/256 color palette, so replacing those colors can make sense.

I would like to avoid using true color if possible, because that adds a lot more places to update whenever I change my color scheme. Also some programs such as WeeChat do not support true color (source).

It looks like foot currently supports updating colors in the 256 color palette through escape sequences, but that doesn't work when launching programs directly from the command line (bypassing the shell), and I really don't like the idea of having my shell handle part of my terminal configuration when the terminal emulator itself has a config file.

I like to make my color schemes compatible with [base16](https://github.com/chriskempson/base16). This is a 16 color palette, but using the 8 bright colors for the extra colors tends to make some programs look terrible. Setting `bold-text-in-bright=no` is not enough, because some applications use SGR 38/48 and still expect colors 8-15 to be consistent with colors 0-7. On the other hand, very few programs make use of the 88/256 color palette, so replacing those colors can make sense. I would like to avoid using true color if possible, because that adds a lot more places to update whenever I change my color scheme. Also some programs such as WeeChat do not support true color ([source](https://github.com/weechat/weechat/issues/1364)). It looks like foot currently supports updating colors in the 256 color palette through escape sequences, but that doesn't work when launching programs directly from the command line (bypassing the shell), and I really don't like the idea of having my shell handle part of my terminal configuration when the terminal emulator itself has a config file.
Owner

I'm a recent convert to base16, so I do see why this would be convenient.

It would also be very easy to add support for, say, a generic colorN = 123456 option in foot.ini. So yeah, why not.

I'm a recent convert to base16, so I do see why this would be convenient. It would also be very easy to add support for, say, a generic `colorN = 123456` option in foot.ini. So yeah, why not.
dnkl added the
enhancement
easy
labels 6 months ago
dnkl referenced this issue from a commit 6 months ago
dnkl closed this issue 6 months ago
dnkl referenced this issue from a commit 6 months ago

Posting this here so that at least you two know about this:

base16 colors for foot are present in https://gitlab.com/ArenM/base16-foot.

It's about to be added in the base16 list in https://github.com/chriskempson/base16-templates-source/pull/97

And the folowing MR adds colors with the 256 palette: https://gitlab.com/ArenM/base16-foot/-/merge_requests/1

Thanks for the addition! It works nicely

Posting this here so that at least you two know about this: base16 colors for foot are present in https://gitlab.com/ArenM/base16-foot. It's about to be added in the base16 list in https://github.com/chriskempson/base16-templates-source/pull/97 And the folowing MR adds colors with the 256 palette: https://gitlab.com/ArenM/base16-foot/-/merge_requests/1 Thanks for the addition! It works nicely
Owner

@paul-ri thanks for letting us know!

I was aware of Aren's work, but not your work on the 256-color palette. It's greatly appreciated!

@paul-ri thanks for letting us know! I was aware of Aren's work, but not your work on the 256-color palette. It's greatly appreciated!
Owner

I've updated my conf to use the 256-color variant of the default dark scheme. Now, I like my bright colors to be, well, bright. Since there aren't any bright colors defined by base16, I decided to do something fairly simple.

I just took the regular1-6 colors, and ran them through a script I wrote that converts the RGB colors to the HSV color space, increases the V-value (makes it brighter) and converts back to RGB:

#!/usr/bin/env python3
import sys
import colorsys
import argparse


def main():
    def hex_argparse_type(s: str):
        try:
            return int(s, base=16)
        except ValueError:
            raise argparse.ArgumentError(f'{s}: not a hexadecimal number')

    parser = argparse.ArgumentParser()
    parser.add_argument(
        'amount', type=float,
        help=('amount to increase the HSV\'s V-value, '
              'in the range 0-1. Saturates to 1.'))
    parser.add_argument(
        'color', type=hex_argparse_type,
        help='color(s) to brighten, in hexadecimal.',
        nargs='*')

    args = parser.parse_args()

    for rgb in args.color:
        r = ((rgb >> 16) & 0xff) / 255
        g = ((rgb >> 8) & 0xff) / 255
        b = ((rgb >> 0) & 0xff) / 255

        h, s, v = colorsys.rgb_to_hsv(r, g, b)
        r, g, b = colorsys.hsv_to_rgb(h, s, min(1, v + args.amount))

        r = int(r * 255)
        g = int(g * 255)
        b = int(b * 255)
        rgb = r << 16 | g << 8 | b
        print(f'{rgb:06x}')


if __name__ == '__main__':
    sys.exit(main())

Running ./brighter 0.5 ab4642 a1b56c ... (on default dark here) produces

ff6862
e2ff98
...

https://codeberg.org/attachments/08017f2a-0c17-4804-92d7-dd3b986e529d

I've updated my conf to use the 256-color variant of the default dark scheme. Now, I like my bright colors to be, well, bright. Since there aren't any bright colors defined by base16, I decided to do something fairly simple. I just took the regular1-6 colors, and ran them through a script I wrote that converts the RGB colors to the HSV color space, increases the V-value (makes it brighter) and converts back to RGB: ```python #!/usr/bin/env python3 import sys import colorsys import argparse def main(): def hex_argparse_type(s: str): try: return int(s, base=16) except ValueError: raise argparse.ArgumentError(f'{s}: not a hexadecimal number') parser = argparse.ArgumentParser() parser.add_argument( 'amount', type=float, help=('amount to increase the HSV\'s V-value, ' 'in the range 0-1. Saturates to 1.')) parser.add_argument( 'color', type=hex_argparse_type, help='color(s) to brighten, in hexadecimal.', nargs='*') args = parser.parse_args() for rgb in args.color: r = ((rgb >> 16) & 0xff) / 255 g = ((rgb >> 8) & 0xff) / 255 b = ((rgb >> 0) & 0xff) / 255 h, s, v = colorsys.rgb_to_hsv(r, g, b) r, g, b = colorsys.hsv_to_rgb(h, s, min(1, v + args.amount)) r = int(r * 255) g = int(g * 255) b = int(b * 255) rgb = r << 16 | g << 8 | b print(f'{rgb:06x}') if __name__ == '__main__': sys.exit(main()) ``` Running `./brighter 0.5 ab4642 a1b56c ... ` (on _default dark_ here) produces ``` ff6862 e2ff98 ... ``` ![https://codeberg.org/attachments/08017f2a-0c17-4804-92d7-dd3b986e529d](https://codeberg.org/attachments/08017f2a-0c17-4804-92d7-dd3b986e529d)
Owner

It's not perfect. For example, the yellow is almost the same since the base16 yellow's V value is almost saturated from the beginning. But for me it's still an improvement.

It's not perfect. For example, the yellow is almost the same since the base16 yellow's V value is almost saturated from the beginning. But for me it's still an improvement.
Poster

Neat! For a while I generated my colors from HSV values as well. This script is no longer in use, but it does account for bright colors.

https://github.com/9ary/dotfiles/blob/master/colors.py

Neat! For a while I generated my colors from HSV values as well. This script is no longer in use, but it does account for bright colors. https://github.com/9ary/dotfiles/blob/master/colors.py
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.