refactor(wezterm): smart-padding function

This commit is contained in:
winston 2023-04-09 23:51:31 +02:00
parent ec0bee34c8
commit e1abe82454
Signed by: winston
GPG key ID: 3786770EDBC2B481
4 changed files with 31 additions and 26 deletions

View file

@ -1,7 +1,7 @@
"$schema" = "https://starship.rs/config-schema.json"
format = """
[ ](bg:red)\
[](fg:red)\
$directory\
$username\
$hostname\

View file

@ -1,25 +0,0 @@
local wezterm = require("wezterm")
local utils = require("utils")
local nonpadded_apps = { "nvim", "btop", "btm" }
wezterm.on("smartpadding", function(window, pane)
local fgp = pane:get_foreground_process_info()
if fgp == nil then
return
elseif utils.tableContains(nonpadded_apps, fgp.name) then
window:set_config_overrides({
window_padding = { left = 0, right = 0, top = 0, bottom = 0 },
})
else
window:set_config_overrides({
window_padding = wezterm.GLOBAL.smart_padding,
})
end
end)
wezterm.on("update-status", function(window, pane)
if wezterm.GLOBAL.smart_padding ~= nil then
wezterm.emit("smartpadding", window, pane)
end
end)

View file

@ -0,0 +1,23 @@
local wezterm = require("wezterm")
local M = {}
M.apply_to_config = function(c)
local default_padding = c.window_padding
wezterm.on("smart-padding", function(window, pane)
if pane:is_alt_screen_active() then
window:set_config_overrides({
window_padding = { left = 0, right = 0, top = 0, bottom = 0 },
})
else
window:set_config_overrides({
window_padding = default_padding,
})
end
end)
wezterm.on("update-status", function(window, pane)
wezterm.emit("smart-padding", window, pane)
end)
end
return M

View file

@ -8,6 +8,13 @@ end
require("fonts").apply(c)
require("keys").apply(c)
c.window_padding = {
left = 10,
right = 10,
top = 10,
bottom = 10,
}
require("smartpadding").apply_to_config(c)
-- set up terminfo on nix
c.set_environment_variables = {