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 utils = require("utils")
local M = {}
@ -39,21 +40,6 @@ local config = {
-- parsed config
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 = {
slant_right = {
left = utf8.char(0xe0be),
@ -82,7 +68,7 @@ M.apply_to_config = function(c, opts)
end
-- combine user config with defaults
config = tableMerge(config, opts)
config = utils.tableMerge(config, opts)
C.div = {
l = "",
r = "",

View file

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

View file

@ -1,17 +1,20 @@
local wezterm = require("wezterm")
local utils = require("utils")
local M = {}
local defaults = {
size = 16,
ui_font = "IBM Plex Sans",
}
-- fonts I like, with the settings I prefer
-- kept separately from the rest of the config so that I can easily change them
local fonts = {
berkeley = {
font = "Berkeley Mono",
size = 16,
},
berkeley = { font = "Berkeley Mono" },
comic = {
font = "Comic Code Ligatures",
size = 16,
ui_font = "xkcd Script",
},
victor = {
font = {
@ -19,10 +22,14 @@ local fonts = {
weight = "DemiBold",
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)
return {
font = wezterm.font_with_fallback({
@ -30,6 +37,7 @@ M.get_font = function(name)
"Symbols Nerd Font",
}),
size = fonts[name].size,
ui_font = wezterm.font(fonts[name].ui_font),
}
end
@ -40,16 +48,25 @@ wezterm.on("switch-font", function(window, _)
end
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({
font = M.get_font(next_font).font,
font_size = M.get_font(next_font).size,
font = f.font,
font_size = f.size,
window_frame = window_frame,
})
end)
wezterm.GLOBAL = { font = "berkeley" }
M.apply = function(c)
c.font = M.get_font(wezterm.GLOBAL.font).font
c.font_size = M.get_font(wezterm.GLOBAL.font).size
local f = M.get_font(wezterm.GLOBAL.font)
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
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.window_frame = {
font = wezterm.font({ family = "IBM Plex Sans" }),
font_size = 18.0,
}