-
-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger color mode change following darkmode or alike in macos #806
Comments
There are some details on how to do this in this thread: |
Hey! So I was trying something similar for Windows theme detection, the relevant code is relatively simple: function compute_scheme()
local success, stdout, stderr = wezterm.run_child_process({"reg", "query", "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "/v", "AppsUseLightTheme"})
local is_light = tonumber(wezterm.truncate_left(wezterm.split_by_newlines(stdout)[3],1))
if is_light == 0 then
return "BlulocoDark";
end
return "BlulocoLight";
end This correctly returns the value, but for some reason the theme doesn't actually change unless wezterm is restarted. Here is my config: local wezterm = require 'wezterm';
function compute_scheme()
local success, stdout, stderr = wezterm.run_child_process({"reg", "query", "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "/v", "AppsUseLightTheme"})
local is_light = tonumber(wezterm.truncate_left(wezterm.split_by_newlines(stdout)[3],1))
if is_light == 0 then
return "BlulocoDark";
end
return "BlulocoLight";
end
wezterm.on("update-right-status", function(window, pane)
local overrides = window:get_config_overrides() or {}
local color_scheme = compute_scheme()
if overrides.color_scheme ~= color_scheme then
overrides.color_scheme = color_scheme
window:set_config_overrides(overrides)
end
end)
return {
launch_menu = {
{ label = "PowerShell", args = {"pwsh"} },
{ label = "Cmd", args = {"cmd"} },
{ label = "Bash", args = {"bash"} },
{ label = "Neovim", args = {"nvim"} },
},
window_padding = {
left = 25,
right = 25,
top = 25,
bottom = 25,
},
initial_cols = 90,
initial_rows = 30,
hide_tab_bar_if_only_one_tab = true,
add_wsl_distributions_to_launch_menu = false,
font = wezterm.font("RecMonoSemicasual NF", {weight="Medium"}),
color_scheme = compute_scheme(),
default_prog = {"pwsh"},
font_size = 11.0,
colors = {
tab_bar = {
background = "#F9F9F9",
active_tab = {
bg_color = "#F9F9F9",
fg_color = "#000000",
intensity = "Bold",
underline = "Single",
},
inactive_tab = {
bg_color = "#F0F0F0",
fg_color = "#808080",
},
inactive_tab_hover = {
bg_color = "#E4E4E4",
fg_color = "#808080",
italic = true,
}
}
}
} What am I doing wrong here? |
This config switches the color scheme based on the appearance: local wezterm = require 'wezterm'
function scheme_for_appearance(appearance)
if appearance:find("Dark") then
return "Builtin Solarized Dark"
else
return "Builtin Solarized Light"
end
end
wezterm.on("window-config-reloaded", function(window, pane)
local overrides = window:get_config_overrides() or {}
local appearance = window:get_appearance()
local scheme = scheme_for_appearance(appearance)
if overrides.color_scheme ~= scheme then
overrides.color_scheme = scheme
window:set_config_overrides(overrides)
end
end)
return {
} The fn get_appearance(&self) -> Appearance {
if let Ok(1) = read_theme() {
Appearance::Light
} else {
Appearance::Dark
}
} in here: https://github.com/wez/wezterm/blob/main/window/src/os/windows/connection.rs#L25 I'll look at this a bit later today, but if you wanted to submit a PR for this before I get to it, go for it! |
Sorry, I won't be able to as I'm caught up with some work today. But I have a question: is the |
The only thing that wasn't hooked up on windows was the window:set_config_overrides is implemented and behaves the same way on all systems. You can use other criteria than the system appearance to influence the config overrides. There are some examples in the docs, and there's an example of using the update right status hook as a timer to do something that might depend on the current time. |
Docs are up at https://wezfurlong.org/wezterm/config/lua/window/get_appearance.html |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Is your feature request related to a problem? Please describe.
In Today's operating systems like macos there is features that allows you to set darkmode at the evening and lightmode at the day, for me that means having a light and a dark theme. from what i have found i don't see a way to do this.
Describe the solution you'd like
Since the way different operating systems works i think one of the options i like is to allow for a background task or ticker. like you can have in vim with a ticker triggering every N sec. this you could then trigger colour theme change for example.
i have a smaller shell script for kitty to handle this looking like this but i use the same logic to conditional change for vim since it's the same macos defaults key
the optimal option would be to have OS specific implementations but that does not have to be the initial option to allow users to solve it
The text was updated successfully, but these errors were encountered: