feat(wezterm): specify & switch ui_font as well

This commit is contained in:
winston 2023-03-06 11:58:51 +01:00
parent a555cd6114
commit e4b2b5aae1
Signed by: winston
GPG key ID: 3786770EDBC2B481
5 changed files with 59 additions and 38 deletions

View file

@ -1,4 +1,5 @@
local wezterm = require("wezterm") local wezterm = require("wezterm")
local utils = require("utils")
local M = {} local M = {}
@ -39,21 +40,6 @@ local config = {
-- parsed config -- parsed config
local C = {} local C = {}
local function tableMerge(t1, t2)
for k, v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
local dividers = { local dividers = {
slant_right = { slant_right = {
left = utf8.char(0xe0be), left = utf8.char(0xe0be),
@ -82,7 +68,7 @@ M.apply_to_config = function(c, opts)
end end
-- combine user config with defaults -- combine user config with defaults
config = tableMerge(config, opts) config = utils.tableMerge(config, opts)
C.div = { C.div = {
l = "", l = "",
r = "", r = "",

View file

@ -1,14 +1,5 @@
local wezterm = require("wezterm") local wezterm = require("wezterm")
local utils = require("utils")
local function arrContains(arr, val)
for _, v in ipairs(arr) do
if v == val then
return true
end
end
return false
end
local nonpadded_apps = { "nvim", "btop", "btm" } local nonpadded_apps = { "nvim", "btop", "btm" }
@ -16,7 +7,7 @@ wezterm.on("smartpadding", function(window, pane)
local fgp = pane:get_foreground_process_info() local fgp = pane:get_foreground_process_info()
if fgp == nil then if fgp == nil then
return return
elseif arrContains(nonpadded_apps, fgp.name) then elseif utils.tableContains(nonpadded_apps, fgp.name) then
window:set_config_overrides({ window:set_config_overrides({
window_padding = { left = 0, right = 0, top = 0, bottom = 0 }, window_padding = { left = 0, right = 0, top = 0, bottom = 0 },
}) })

View file

@ -1,17 +1,20 @@
local wezterm = require("wezterm") local wezterm = require("wezterm")
local utils = require("utils")
local M = {} local M = {}
local defaults = {
size = 16,
ui_font = "IBM Plex Sans",
}
-- fonts I like, with the settings I prefer -- fonts I like, with the settings I prefer
-- kept separately from the rest of the config so that I can easily change them -- kept separately from the rest of the config so that I can easily change them
local fonts = { local fonts = {
berkeley = { berkeley = { font = "Berkeley Mono" },
font = "Berkeley Mono",
size = 16,
},
comic = { comic = {
font = "Comic Code Ligatures", font = "Comic Code Ligatures",
size = 16, ui_font = "xkcd Script",
}, },
victor = { victor = {
font = { font = {
@ -19,10 +22,14 @@ local fonts = {
weight = "DemiBold", weight = "DemiBold",
harfbuzz_features = { "ss02=1" }, harfbuzz_features = { "ss02=1" },
}, },
size = 15, size = defaults.size - 1,
}, },
} }
for k, v in pairs(fonts) do
fonts[k] = utils.tableMerge(v, defaults)
end
M.get_font = function(name) M.get_font = function(name)
return { return {
font = wezterm.font_with_fallback({ font = wezterm.font_with_fallback({
@ -30,6 +37,7 @@ M.get_font = function(name)
"Symbols Nerd Font", "Symbols Nerd Font",
}), }),
size = fonts[name].size, size = fonts[name].size,
ui_font = wezterm.font(fonts[name].ui_font),
} }
end end
@ -40,16 +48,25 @@ wezterm.on("switch-font", function(window, _)
end end
wezterm.GLOBAL.font = next_font wezterm.GLOBAL.font = next_font
local f = M.get_font(next_font)
local window_frame = window:effective_config().window_frame
window_frame = utils.tableMerge({ font = f.ui_font }, window_frame)
window:set_config_overrides({ window:set_config_overrides({
font = M.get_font(next_font).font, font = f.font,
font_size = M.get_font(next_font).size, font_size = f.size,
window_frame = window_frame,
}) })
end) end)
wezterm.GLOBAL = { font = "berkeley" } wezterm.GLOBAL = { font = "berkeley" }
M.apply = function(c) M.apply = function(c)
c.font = M.get_font(wezterm.GLOBAL.font).font local f = M.get_font(wezterm.GLOBAL.font)
c.font_size = M.get_font(wezterm.GLOBAL.font).size c.font = f.font
c.font_size = f.size
if c.window_frame == nil then
c.window_frame = {}
end
c.window_frame.font = f.ui_font
end end
return M return M

View file

@ -0,0 +1,28 @@
local M = {}
M.tableMerge = function(t1, t2)
for k, v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
M.tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
M.tableContains = function(t, val)
for _, v in ipairs(t) do
if v == val then
return true
end
end
return false
end
return M

View file

@ -37,7 +37,6 @@ c.launch_menu = {
} }
c.command_palette_font_size = 16.0 c.command_palette_font_size = 16.0
c.window_frame = { c.window_frame = {
font = wezterm.font({ family = "IBM Plex Sans" }),
font_size = 18.0, font_size = 18.0,
} }