feat: wezterm theme switching
This commit is contained in:
1 parent
58ec82092c
commit
a3a9472799
4 files changed
+87
-43
No files matched your search
@@ -33,11 +33,27 @@
|
|||||||
relativenumber = true;
|
relativenumber = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Define the global helper function so you can run :lua set_wezterm_theme('solid') anytime
|
||||||
|
extraConfigLua = ''
|
||||||
|
_G.set_wezterm_theme = function(theme)
|
||||||
|
local val = theme or ""
|
||||||
|
local b64 = vim.base64.encode(val)
|
||||||
|
local seq = string.format('\x1b]1337;SetUserVar=%s=%s\x07', 'WEZTERM_THEME', b64)
|
||||||
|
|
||||||
|
if vim.env.TMUX then
|
||||||
|
seq = string.format('\x1bPtmux;\x1b%s\x1b\\', seq)
|
||||||
|
end
|
||||||
|
|
||||||
|
pcall(vim.fn.chansend, vim.v.stderr, seq)
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
|
||||||
autoGroups = {
|
autoGroups = {
|
||||||
WezTermUserVar = {
|
WezTermUserVar = {
|
||||||
clear = true;
|
clear = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
autoCmd = [
|
autoCmd = [
|
||||||
# --- Sets tab spacing for file types ---
|
# --- Sets tab spacing for file types ---
|
||||||
{
|
{
|
||||||
@@ -53,34 +69,26 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
# --- Set default WezTerm profile on entry/resume ---
|
||||||
{
|
{
|
||||||
event = [ "UIEnter" "VimResume" ];
|
event = [ "UIEnter" "VimResume" ];
|
||||||
group = "WezTermUserVar";
|
group = "WezTermUserVar";
|
||||||
callback = {
|
callback = {
|
||||||
__raw = ''
|
__raw = ''
|
||||||
function()
|
function()
|
||||||
local b64 = vim.base64.encode('true')
|
set_wezterm_theme('nvim')
|
||||||
local seq = string.format('\x1b]1337;SetUserVar=%s=%s\x07', 'IS_NVIM', b64)
|
|
||||||
if vim.env.TMUX then
|
|
||||||
seq = string.format('\x1bPtmux;\x1b%s\x1b\\', seq)
|
|
||||||
end
|
|
||||||
pcall(vim.fn.chansend, vim.v.stderr, seq)
|
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
# --- Clear WezTerm profile (revert to base config) on exit/suspend ---
|
||||||
{
|
{
|
||||||
event = [ "VimLeavePre" "VimSuspend" ];
|
event = [ "VimLeavePre" "VimSuspend" ];
|
||||||
group = "WezTermUserVar";
|
group = "WezTermUserVar";
|
||||||
callback = {
|
callback = {
|
||||||
__raw = ''
|
__raw = ''
|
||||||
function()
|
function()
|
||||||
local b64 = vim.base64.encode('false')
|
set_wezterm_theme("")
|
||||||
local seq = string.format('\x1b]1337;SetUserVar=%s=%s\x07', 'IS_NVIM', b64)
|
|
||||||
if vim.env.TMUX then
|
|
||||||
seq = string.format('\x1bPtmux;\x1b%s\x1b\\', seq)
|
|
||||||
end
|
|
||||||
pcall(vim.fn.chansend, vim.v.stderr, seq)
|
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local config = wezterm.config_builder()
|
|||||||
-- Launch fish directly instead of your system login shell
|
-- Launch fish directly instead of your system login shell
|
||||||
config.default_prog = { 'fish', '-l' }
|
config.default_prog = { 'fish', '-l' }
|
||||||
|
|
||||||
-- Appearance & Tab Bar
|
-- Base Appearance & Tab Bar (Default / Fallback state)
|
||||||
config.window_background_opacity = 0.60
|
config.window_background_opacity = 0.60
|
||||||
config.wayland_window_background_blur = true
|
config.wayland_window_background_blur = true
|
||||||
config.hide_tab_bar_if_only_one_tab = true
|
config.hide_tab_bar_if_only_one_tab = true
|
||||||
@@ -21,47 +21,90 @@ config.colors = {
|
|||||||
foreground = '#dddddd',
|
foreground = '#dddddd',
|
||||||
}
|
}
|
||||||
|
|
||||||
local bg_image_path = wezterm.config_dir .. '/texture.png'
|
-- Helper to safely check if a file exists before applying it
|
||||||
|
local function file_exists(path)
|
||||||
|
if not path then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local f = io.open(path, 'r')
|
||||||
|
if f then
|
||||||
|
f:close()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local function sync_nvim_appearance(window, pane)
|
-- Define arbitrary theme profiles here.
|
||||||
|
-- Keys correspond to the value of the WEZTERM_THEME user variable.
|
||||||
|
local profiles = {
|
||||||
|
nvim = {
|
||||||
|
colors = { foreground = '#ffffff' },
|
||||||
|
window_background_image = wezterm.config_dir .. '/texture.png',
|
||||||
|
window_background_opacity = 1.0,
|
||||||
|
},
|
||||||
|
solid = {
|
||||||
|
colors = { foreground = '#eeeeee', background = '#1e1e2e' },
|
||||||
|
window_background_opacity = 1.0,
|
||||||
|
},
|
||||||
|
light = {
|
||||||
|
colors = { foreground = '#111111', background = '#f5f5f5' },
|
||||||
|
window_background_opacity = 0.95,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Track the active profile per window so we don't trigger redundant reloads
|
||||||
|
local active_window_profiles = {}
|
||||||
|
|
||||||
|
local function sync_appearance(window, pane)
|
||||||
if not pane then
|
if not pane then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local user_vars = pane:get_user_vars()
|
local user_vars = pane:get_user_vars()
|
||||||
local is_nvim = user_vars.IS_NVIM == 'true'
|
local target_profile = user_vars.WEZTERM_THEME or 'default'
|
||||||
local overrides = window:get_config_overrides() or {}
|
local win_id = window:window_id()
|
||||||
|
|
||||||
-- Avoid redundant config reloads if state hasn't changed
|
-- Skip if this window is already using the requested profile
|
||||||
local currently_active = overrides.window_background_image ~= nil
|
if active_window_profiles[win_id] == target_profile then
|
||||||
if is_nvim == currently_active then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_nvim then
|
local profile_settings = profiles[target_profile]
|
||||||
overrides.colors = {
|
|
||||||
foreground = '#ffffff',
|
|
||||||
}
|
|
||||||
overrides.window_background_opacity = 1.0
|
|
||||||
overrides.window_background_image = bg_image_path
|
|
||||||
else
|
|
||||||
overrides.colors = nil
|
|
||||||
overrides.window_background_opacity = nil
|
|
||||||
overrides.window_background_image = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
window:set_config_overrides(overrides)
|
if profile_settings then
|
||||||
|
local overrides = {}
|
||||||
|
|
||||||
|
-- Copy arbitrary settings from the chosen profile
|
||||||
|
for key, value in pairs(profile_settings) do
|
||||||
|
overrides[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fallback: If a background image is specified, verify the file exists.
|
||||||
|
-- If missing, drop the image override and restore base opacity so text stays readable.
|
||||||
|
if overrides.window_background_image and not file_exists(overrides.window_background_image) then
|
||||||
|
wezterm.log_warn('Background image not found: ' .. overrides.window_background_image)
|
||||||
|
overrides.window_background_image = nil
|
||||||
|
overrides.window_background_opacity = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
window:set_config_overrides(overrides)
|
||||||
|
active_window_profiles[win_id] = target_profile
|
||||||
|
else
|
||||||
|
-- Reset to base config if the variable is unset, empty, or unrecognized
|
||||||
|
window:set_config_overrides({})
|
||||||
|
active_window_profiles[win_id] = 'default'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
wezterm.on('user-var-changed', function(window, pane, name, _value)
|
wezterm.on('user-var-changed', function(window, pane, name, _value)
|
||||||
if name == 'IS_NVIM' then
|
if name == 'WEZTERM_THEME' then
|
||||||
sync_nvim_appearance(window, pane)
|
sync_appearance(window, pane)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Also sync when switching tabs or closing panes
|
-- Keep state synced when switching tabs or closing panes
|
||||||
wezterm.on('update-status', function(window, pane)
|
wezterm.on('update-status', function(window, pane)
|
||||||
sync_nvim_appearance(window, pane)
|
sync_appearance(window, pane)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
@@ -25,7 +25,6 @@ in
|
|||||||
|
|
||||||
../common/users/Winter/default.nix
|
../common/users/Winter/default.nix
|
||||||
../common/features/DesktopNiri.nix
|
../common/features/DesktopNiri.nix
|
||||||
../common/features/DesktopKDEPlasma.nix
|
|
||||||
../common/features/Applications.nix
|
../common/features/Applications.nix
|
||||||
#../common/features/servers/minecraft.nix
|
#../common/features/servers/minecraft.nix
|
||||||
|
|
||||||
@@ -61,9 +60,6 @@ in
|
|||||||
home-manager = {
|
home-manager = {
|
||||||
extraSpecialArgs = { inherit inputs; };
|
extraSpecialArgs = { inherit inputs; };
|
||||||
backupFileExtension = "backup";
|
backupFileExtension = "backup";
|
||||||
users = {
|
|
||||||
Winter = import ../../home/Winter/Winter/${hostname}.nix;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
|
|||||||
@@ -60,9 +60,6 @@ in
|
|||||||
home-manager = {
|
home-manager = {
|
||||||
extraSpecialArgs = { inherit inputs; };
|
extraSpecialArgs = { inherit inputs; };
|
||||||
backupFileExtension = "backup";
|
backupFileExtension = "backup";
|
||||||
users = {
|
|
||||||
EXAMPLE = import ../../../home/EXAMPLE/EXAMPLE/${hostname}.nix; # FIXME
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
|
|||||||
Reference in new issue
Block a user