kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.85k stars 997 forks source link

light/dark theme based on system? #4915

Closed hanoii closed 2 years ago

hanoii commented 2 years ago

Is your feature request related to a problem? Please describe. I normally use a dark setting systemwide, but also sometimes I am outdoors and prefer a light theme for most and I would like a light one on kitty.

Describe the solution you'd like I'd like a setting to set a default theme, a light theme and and or a dark theme. You could have a setting to enable this but I assume it's redundant, if you only select a default theme, there would be no change, if there's a light/dark theme configured, it will favour that over the default depending on the system setting.

kovidgoyal commented 2 years ago

Not something I care enough to implement. It's trivially easy to implement this yourself by using the themes kitten. Simply have your system run a script when the theme changes and in that script call the themes kitten to change the theme in all kitty instances.

hanoii commented 2 years ago

How didn't I think of that?!

Looking around it seems https://github.com/bouk/dark-mode-notify for osx is a kickstart I'll be trying out, if anyone stumbles upon something different/better let me know.

EDIT:

#!/bin/bash

if [[ "$DARKMODE" -eq 1 ]]; then
    kitty +kitten themes --reload-in=all Snazzy 
fi

if [[ "$DARKMODE" -eq 0 ]]; then
    kitty +kitten themes --reload-in=all Material
fi

does it :)

Joxtacy commented 2 years ago

@hanoii Did you manage to figure out a solution? How often/when do you run your script to check the $DARKMODE variable?

The slightly annoying thing with this approach is all the separate moving parts to it.

hanoii commented 2 years ago

@Joxtacy yes, it was sorted out by what explained in the other post. I don't have to poll anything, that small program linked https://github.com/kovidgoyal/kitty/issues/4915#issuecomment-1088016786 runs the script whenever the setting changes. It's just one tiny think on top of the thousands I manage :)

rkshthrmsh commented 1 year ago

Hi @hanoii, I was able to build and test dark-mode-notify with Kitty from command line, but for some reason I'm unable to get the Background Agent launchctl load -w to automatically listen, launch, and execute the command on system mode change. Any help is appreciated.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>ke.bou.dark-mode-notify</string>
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/dark-mode-notify-stderr.log</string>
    <key>StandardOutPath</key>
    <string>/tmp/dark-mode-notify-stdout.log</string>
    <key>ProgramArguments</key>
    <array>
       <string>/usr/local/bin/dark-mode-notify</string>
       <string>/Users/user/.config/kitty/system_based_theme.zsh</string>
    </array>
</dict>
</plist>

EDIT: I had to modify the bash script from hanoii above to provide full path to kitty's binary. Like so:

#!/bin/zsh

if [[ "$DARKMODE" -eq 0 ]]; then
    /Applications/kitty.app/Contents/MacOS/kitty +kitten themes --reload-in=all Rosé Pine Dawn 
fi

if [[ "$DARKMODE" -eq 1 ]]; then
    /Applications/kitty.app/Contents/MacOS/kitty +kitten themes --reload-in=all Rosé Pine Moon
fi

Figured it out thanks to the error logs (which I was not using previously)

gaheldev commented 1 year ago

For people using Gnome, I made a script that does it: https://github.com/gaheldev/kitty-gnome-lightdark-mode-switcher Probably easy to adapt to KDE too. It feels very hacky but works for me so far.

jannis-baum commented 1 year ago

I case anyone is interested: I made a script that lets you generate your own color-schemes (for Kitty, Vim, and other programs) that allow you to reload the colors entirely dynamically, i.e. the entire scrollback is adjusted and you never have to worry about reloading anything but kitty!

The repo also includes instructions for how to make Kitty automatically change the theme in sync with the macOS system dark/light mode.

See Chameleon.

h-jia commented 1 year ago

Toggle Theme.zip I made an alfred workflow to do this. It changes your system themes and kitty's at the same time.

iclanzan commented 4 months ago

Curiously Kitty is already tracking changes to the system theme but all it does is print the string "system color theme changed: dark/light".

kovidgoyal commented 4 months ago

Nothing curious about it, the tracking is used to change the window decoration colors on GNOME Wayland.

And see https://github.com/kovidgoyal/kitty-fosshack2024/issues/3

kovidgoyal commented 1 month ago

Dont see why? If someone want to use a high contrast theme for light/dark they could just set that as the light or dark theme. I know of no OS that auto switches between 4 different color themes, do you?

kovidgoyal commented 1 month ago

It isnt exposed over DBUS so even if the OS supports it, kitty would not be able to use it.

kovidgoyal commented 1 month ago

I still dont follow. What would a separate setting achieve? kitty cannot know if the OS is in high contrast mode or not. So how would it ever use such a setting.

kovidgoyal commented 1 month ago

On Sun, Nov 03, 2024 at 07:12:06PM -0800, klmcwhirter wrote:

Yes it can. But I suspect there may be some other mechanism required to detect it.

There is no DE independent mechanism that I know of. Indeed as far as I know there is no DE independent high contrast setting available in Linux. The best you can get is a "high contrast" icon theme.

To support it VS Code supplies separate settings.

This will almost certainly be legacy code inherited to support Windows' high contrast themes.

This info is only useful to try to future proof the design of the settings now to just support dark / light switching. If they are separate settings now, using whatever convention you come up with, it might be easier to expand the concept later to include high contrast, etc. support later.

I doubt there will ever be a need for them. High contrast is a holdover from Linux DEs trying to copy windows which used to have these. But regardless, if it ever became a thing one could simply add two more optional entries to the list of themes in the kitty setting, specifying different themes for high contrast mode.

klmcwhirter commented 4 weeks ago

FYI

I have an implementation of a kitty "watcher" that is doing the job of monitoring the dark/light color scheme system changes for me. I am hesitant to share the code because it is an unorthodox approach; but it works for me.

Assumptions: