Skip to content

Commit

Permalink
chore: update mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
fisenkodv authored Oct 10, 2024
1 parent 270ae1c commit d7b9d04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/wezterm/cfg_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function M.setup(cfg)
{ key = "Escape", mods = "CTRL", action = wezterm.action.ShowDebugOverlay },

{ key = "w", mods = "CMD", action = wezterm.action.CloseCurrentTab({ confirm = true }) },
{ key = "t", mods = "ALT", action = wezterm.action_callback(utils.theme_cycler) },
{ key = "t", mods = "ALT", action = wezterm.action_callback(utils.theme_switcher) },

{ key = "[", mods = "LEADER", action = act.ActivateTabRelative(-1) },
{ key = "]", mods = "LEADER", action = act.ActivateTabRelative(1) },
Expand Down
56 changes: 27 additions & 29 deletions config/wezterm/lib/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,36 @@ function M.tab_title(tab_info)
return tab_info.active_pane.title
end

---cycle through builtin dark schemes in dark mode,
---and through light schemes in light mode
function M.theme_cycler(window, _)
local allSchemes = wezterm.color.get_builtin_schemes()
local currentAppearance = wezterm.gui.get_appearance()
local currentScheme = window:effective_config().color_scheme
local darkSchemes = {}
local lightSchemes = {}
M.theme_switcher = function(window, pane)
-- get builting color schemes
local schemes = wezterm.get_builtin_color_schemes()
local choices = {}

for name, scheme in pairs(allSchemes) do
if scheme.background then
local bg = wezterm.color.parse(scheme.background) -- parse into a color object
---@diagnostic disable-next-line: unused-local
local h, s, l, a = bg:hsla() -- and extract HSLA information
if l < 0.4 then
table.insert(darkSchemes, name)
else
table.insert(lightSchemes, name)
end
end
-- populate theme names in choices list
for key, _ in pairs(schemes) do
table.insert(choices, { label = tostring(key) })
end
local schemesToSearch = darkSchemes -- currentAppearance:find("Dark") and darkSchemes or lightSchemes

for i = 1, #schemesToSearch, 1 do
if schemesToSearch[i] == currentScheme then
local overrides = window:get_config_overrides() or {}
overrides.color_scheme = schemesToSearch[i + 1]
wezterm.log_info("Switched to: " .. schemesToSearch[i + 1])
window:set_config_overrides(overrides)
return
end
end
-- sort choices list
table.sort(choices, function(c1, c2)
return c1.label < c2.label
end)

window:perform_action(
act.InputSelector({
title = "🎨 Pick a Theme!",
choices = choices,
fuzzy = true,

action = wezterm.action_callback(function(_, _, _, label)
local overrides = window:get_config_overrides() or {}
overrides.color_scheme = label
wezterm.log_info("Switched to: " .. label)
window:set_config_overrides(overrides)
end),
}),
pane
)
end

return M

0 comments on commit d7b9d04

Please sign in to comment.