feat: remove padding from kitty terminal on startup

This commit is contained in:
Youwen Wu 2024-11-01 13:54:16 -07:00
parent 0aca102f57
commit 474c38a272
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
2 changed files with 59 additions and 0 deletions

View file

@ -29,6 +29,7 @@ vim.opt.scrolloff = 10
if os.getenv("TERM") == "xterm-kitty" then
require("scripts.chameleon").setup()
require("scripts.kitty-padding").setup()
end
vim.cmd.colorscheme("rose-pine")

View file

@ -0,0 +1,58 @@
-- remove padding from kitty terminal when entering vim
local M = {}
local fn = vim.fn
local api = vim.api
local autocmd = api.nvim_create_autocmd
local autogroup = api.nvim_create_augroup
local no_padding = function(sync)
local command = "kitty @ set-spacing padding-h=0 padding-bottom=0"
if not sync then
fn.jobstart(command, {
on_stderr = function(_, d, _)
if #d > 1 then
api.nvim_err_writeln("Error setting window padding. Make sure kitty remote control is turned on.")
end
end,
})
else
fn.system(command)
end
end
local restore_padding = function(sync)
local command = "kitty @ set-spacing padding=default"
if not sync then
fn.jobstart(command, {
on_stderr = function(_, d, _)
if #d > 1 then
api.nvim_err_writeln("Error setting window padding. Make sure kitty remote control is turned on.")
end
end,
})
else
fn.system(command)
end
end
M.setup = function()
autocmd({ "VimResume", "VimEnter" }, {
pattern = "*",
callback = function()
no_padding()
end,
group = autogroup("SpacingRemove", { clear = true }),
})
autocmd({ "VimLeavePre", "VimSuspend" }, {
callback = function()
restore_padding(true)
end,
group = autogroup("SpacingRestore", { clear = true }),
})
end
return M