Conversation
|
I am somewhat confused as to how this is supposed to work. The default options have all 256 colors defined. So generate_256_colors will always default to False. patch_colors() is used when dynamically changing colors at runtime only, not for initial creation of the color table. Maybe I am missing something, but in any case this is academic as I think we should use a different approach, see below. Seems to me the better way to do this is to have the default values for the 256 color table > 15 be None using to_color_or_none. And to fill in the values for all None colors based on the first 16 colors, when transferring those color to the C color_table in colors.c. This will require porting your color generation code to C but that should not be too hard since its simple math, and will be good for performance. There are likely to be some subtleties in the implementation here. You will need to possibly use -1 for None colors in color_table as generated in options/types.py and handle None values in getattr/setattr there as well. It might also make sense to have the algorithm generating the 256 colors to take into account some "sentinel" colors if they are not None, beyond the first 16 colors, allowing the user to further fine tune, for instance how red the red are and so on. Finally I'd like to see the changes in the default 256 color table comparing the current default values to the generated ones. Changing the default color table is a fairly big deal so, I would like an idea of how disruptive it will be. |
|
Hmm, that is quite a large difference. That said, I do like your idea in principle. Perhaps, if we go ahead, we should add a "kitty classic" or similarly named theme to kitty-themes so people can revert to the old color table with a single command. It might also make sense to adjust the 16 colors in the default theme a little to reduce the amount of change while preserving the readability benefits. Finally, if you want this approach to be adopted more widely the algorithm, rationale, etc should be documented/specified in a rst file in docs and linked to from the kitty.conf docs. Bottom line: I am OK in principle with doing this. The devil is in the details which will need to be discussed ironed out as this PR matures. |
I have been working on this the last few days. I think it is ok: https://github.com/jake-stewart/color256/blob/main/writeup/readme.md |
|
Looks ok to me. |
|
I think it is looking good.
I was unable to test the docs locally since sphinx is crashing for me. |
|
OK will take a look when I have some time. Am rather swamped at the |
|
My grain of sand, shouldn't this use OkLab instead of Lab? |
|
@leiserfg @edwardgalligan OKLAB was not a perfect drop-in replacement for CIELAB. CIELAB is widely recognized of having accurate lightness values. OKLAB had inconsistent lightness across different themes that even toe lightness correction and gamut clipping failed to properly fix (approaches laid out by the colorspace's creator). For this use case, consistent lightness is far more important than the advantages OKLAB offers. Since consistent shades across different themes share the same meaning. You can view the discussion, approaches, findings here: This PR remains correct with CIELAB. |
|
This PR is not ready: There is active discussion at the Ghostty repo about approaching this slightly differently. The idea is that light themes should not invert the palette so that ansi 16 remains black. This is with the intention of removing the breaking change of generating by default. Then, an opt-in option for "harmonious" colors which inverts the colors for light themes since there are advantages for doing so. |
|
Looks like there is quite a lot of breakage involved in having this. Possibly the way to go is to detect if the theme configured by the user Maybe we should rethink this approach. What is the actual end goal? Make it possible for the user to specify a few colors in one place and The problem is 8/16 colors arent enough so we would like to extend that The current approach is to try and force this for all applications by Maybe a better approach is to advertise the colors explicitly I don't personally have strong feelings about this since I don't use the I do however hate to break existing setups for kitty users. Thus almost I am fairly sure a significant number of users use apps like vim with |
|
Maybe it makes sense to have the autogeneration to be opt-in? So, if something looks off, users know why. |
The new approach is to detect light/dark theme based on the user's fg and bg. Then, generate the palette so that 16=black and 231=white. Light themes would remain inconsistent but significant breaking changes would be avoided. A new opt-in configuration option to enable "harmonious" colours would allow light themes to be inverted so that they are semantically correct.
The plan is that terminal programs will be able to query for FG, BG, color16 and color231. If BG=color16 and FG=color231 then the palette is harmonious and can be used semantically. Otherwise, detect light theme (BG lighter than FG) and invert the indexes if so. This is for terminal program maintainers who care. I am sure most users would just enable harmonious colors and use the palette as intended. |
|
On Thu, Feb 19, 2026 at 11:07:57PM -0800, jake-stewart wrote:
jake-stewart left a comment (kovidgoyal/kitty#9426)
> Possibly the way to go is to detect if the theme configured by the user
assumes colors are background related or dark/light related, by checking
the first 16 values. And then generate the color cube accordingly.
The new approach is to detect light/dark theme based on the user's fg and bg. Then, generate the palette so that 16=black and 231=white. Light themes will be as inconsistent as they were before but without significant breaking changes.
That is definitely less disruptive, but I can guarantee I will see at
least a few issues about background colors changing shade. Just see all
the recent issues from hyprland breaking color management and hence
changing colors in kitty by a few percent in a recent update.
That said, it might still be worth the noise.
A new opt-in configuration option to enable "harmonious" colours would allow light themes to be inverted so that they are semantically correct.
> application developers then cannot rely on the semantics of the palette
The plan is that terminal programs will be able to query for FG, BG, color16 and color231. If FG=color16 and BG=color231 then the palette is harmonious and can be used semantically. Otherwise, detect light theme (FG darker than BG) and invert the indexes if so.
This is for terminal program maintainers who care. I am sure most users would just enable harmonious colors and use the palette as intended.
Terminal program developers have been able to query the color palette
for years now: https://sw.kovidgoyal.net/kitty/color-stack/#setting-and-querying-colors
No one cared :)
|
I think another big problem is that the labels for those 8/16 colors are just names of colors. There isn't any semantic meaning to them, or standard on how those colors should be used. Depending on the color scheme "blue" might have high contrast with the foreground or the background. Even if you can query the true color value of all the colors, using that to figure out the amount of contrast between them all and decide the right way to use them would be pretty complicated. I wonder if maybe a better solution would be for there to be some standard file format for a color scheme that could be re-used across terminal applications. And perhaps have a way for an application to query the terminal for that data so it could be accessed across a remote connection? |
|
This PR is tested and ready. It adds two configuration options that are both opt-in:
The config and behaviour is consistent with other PRs/emulators. The default 256-color palette interpolates from black to white. This means it works better for dark themes since the dark shades are closer to the background and light shades are closer to the foreground. For light themes, the opposite is true, and so a UI designed for dark themes using the default 256-color palette looks bad with light themes. That is the purpose of the The |
|
OK will review when I have a moment. |



#9408
I believe it would benefit the terminal ecosystem greatly if 256 palettes were generated automatically based on user configured base16 themes since consistency by default would convince more developers to use these colors and gain greater flexibility in their color usage without having to increase the complexity of their programs.
To achieve this, I have added an option
generate_256_palettewhich is true unless manually disabled or when one of the 16-255 colors are set. This flag also helps avoid having to check the 256 palette against defaults to determine whether generation is required.I consider it important for themes to share similar contrast ratios between their darkest shades and backgrounds. This ensures themes are interchangeable and prevents users from needing to adjust which shades they use per theme. The logic for this is fast and involves zero looping.