powerline for real

This commit is contained in:
Zacharias-Brohn
2025-12-16 22:50:48 +01:00
parent 04ef946d97
commit d45e5e7b62
+29 -50
View File
@@ -12,7 +12,6 @@ local M = {}
-- Track if statusline integration is active -- Track if statusline integration is active
M._statusline_enabled = false M._statusline_enabled = false
M._statusline_augroup = nil
-- Default configuration -- Default configuration
M.config = { M.config = {
@@ -266,36 +265,42 @@ local function get_rendered_statusline()
return table.concat(output) return table.concat(output)
end end
-- Update the ZTerm statusline -- Polling timer for statusline updates
local function update_statusline() local poll_timer = nil
local last_statusline = nil
-- Check if statusline changed and send update if needed
local function poll_statusline()
if not M._statusline_enabled then if not M._statusline_enabled then
return return
end end
local content = get_rendered_statusline() local content = get_rendered_statusline()
if content then if content and content ~= last_statusline then
last_statusline = content
send_statusline(content) send_statusline(content)
end end
end end
-- Debounce timer for statusline updates -- Start polling for statusline changes
local update_timer = nil local function start_polling()
if poll_timer then
-- Schedule a statusline update with debouncing return
local function schedule_update()
-- Cancel any pending update
if update_timer then
update_timer:stop()
update_timer:close()
update_timer = nil
end end
-- Schedule a new update poll_timer = vim.loop.new_timer()
update_timer = vim.loop.new_timer() -- Poll every 25ms
update_timer:start(5, 0, vim.schedule_wrap(function() poll_timer:start(0, 25, vim.schedule_wrap(poll_statusline))
update_timer = nil end
update_statusline()
end)) -- Stop polling
local function stop_polling()
if poll_timer then
poll_timer:stop()
poll_timer:close()
poll_timer = nil
end
last_statusline = nil
end end
-- Saved laststatus value to restore on disable -- Saved laststatus value to restore on disable
@@ -315,31 +320,8 @@ function M.enable_statusline()
vim.o.laststatus = 0 vim.o.laststatus = 0
end end
-- Create autocommands for statusline updates -- Start polling for statusline changes
M._statusline_augroup = vim.api.nvim_create_augroup("ZTermStatusline", { clear = true }) start_polling()
-- Events that should trigger a statusline update
local events = {
"ModeChanged", -- Mode changes (normal, insert, visual, etc.)
"BufEnter", -- Entering a buffer
"BufWritePost", -- After writing a file
"FileChangedShellPost",
"WinEnter", -- Entering a window
"CursorMoved", -- Cursor moved (for position info)
"CursorMovedI", -- Cursor moved in insert mode
"DiagnosticChanged", -- LSP diagnostics changed
}
vim.api.nvim_create_autocmd(events, {
group = M._statusline_augroup,
callback = function()
-- Use vim.schedule to defer until after the event is fully processed
vim.schedule(update_statusline)
end,
})
-- Initial update
update_statusline()
end end
-- Disable statusline integration -- Disable statusline integration
@@ -350,11 +332,8 @@ function M.disable_statusline()
M._statusline_enabled = false M._statusline_enabled = false
-- Remove autocommands -- Stop polling
if M._statusline_augroup then stop_polling()
vim.api.nvim_del_augroup_by_id(M._statusline_augroup)
M._statusline_augroup = nil
end
-- Restore neovim's statusline -- Restore neovim's statusline
if M._saved_laststatus then if M._saved_laststatus then