fix: replace progress bar with simple notify-based update tracking

This commit is contained in:
swaits committed 2026-04-09 23:17:09 -06:00
1 parent 979ff7548f
commit bd4e6456d1
2 files changed
+17 -85

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
-ck remove PackFetch
- audit thethethe.nvim for tiny'ization
- what else can we remove from our config?
+14 -85
View File
@@ -1,11 +1,9 @@
-- tiny-packupdate.nvim: minimal vim.pack updater with progress bar & results picker -- tiny-packupdate.nvim: minimal vim.pack updater with results picker
-- Requires Neovim 0.12+ (vim.pack API) -- Requires Neovim 0.12+ (vim.pack API)
local M = {} local M = {}
local state = nil -- nil = idle; table = running local state = nil -- nil = idle; table = running
local cfg = { command = "PackUpdate", auto = "manual" } local cfg = { command = "PackUpdate", auto = "manual" }
local ns = vim.api.nvim_create_namespace("tiny-packupdate")
local BAR_W = 40
local LOG_FMT = "--pretty=format:commit %h%nAuthor: %an%nDate: %cr%n%n %s%n" local LOG_FMT = "--pretty=format:commit %h%nAuthor: %an%nDate: %cr%n%n %s%n"
-- ── Timestamp persistence (for auto-update cadence) ─────────────────── -- ── Timestamp persistence (for auto-update cadence) ───────────────────
@@ -31,70 +29,16 @@ local function write_stamp()
end end
end end
-- ── Progress bar UI ───────────────────────────────────────────────────
local function progress_draw()
if not state or not state.buf or not vim.api.nvim_buf_is_valid(state.buf) then
return
end
local elapsed = (vim.uv.hrtime() - state.t0) / 1e9
local pct = state.complete and 1.0 or (0.9 * (1 - math.exp(-elapsed / 5)))
local tag = state.changed > 0 and string.format(" %d new ", state.changed) or ""
local bw = BAR_W - 2 - #tag
local filled = math.floor(pct * bw)
local line = " " .. string.rep("█", filled) .. string.rep("░", bw - filled) .. tag
vim.api.nvim_buf_set_lines(state.buf, 0, -1, false, { line })
vim.api.nvim_buf_clear_namespace(state.buf, ns, 0, -1)
if filled > 0 then
-- █ is 3 bytes in UTF-8
vim.api.nvim_buf_add_highlight(state.buf, ns, "TinyPackProgress", 0, 1, 1 + filled * 3)
end
end
local function progress_open()
local buf = vim.api.nvim_create_buf(false, true)
vim.bo[buf].bufhidden = "wipe"
state.buf = buf
state.win = vim.api.nvim_open_win(buf, false, {
relative = "editor",
row = math.floor(vim.o.lines / 3),
col = math.floor((vim.o.columns - BAR_W) / 2),
width = BAR_W,
height = 1,
style = "minimal",
border = "rounded",
title = " " .. cfg.command .. " ",
title_pos = "center",
noautocmd = true,
})
state.t0 = vim.uv.hrtime()
state.anim = vim.uv.new_timer()
state.anim:start(0, 16, vim.schedule_wrap(progress_draw))
end
local function progress_close()
if not state then
return
end
if state.anim then
state.anim:stop()
state.anim:close()
state.anim = nil
end
if state.win and vim.api.nvim_win_is_valid(state.win) then
vim.api.nvim_win_close(state.win, true)
end
end
-- ── Results display ─────────────────────────────────────────────────── -- ── Results display ───────────────────────────────────────────────────
local function show_results(results) local function show_results(results)
progress_close()
if #results == 0 then if #results == 0 then
vim.notify("All plugins up to date", vim.log.levels.INFO) vim.notify("All plugins already up to date", vim.log.levels.INFO)
state = nil state = nil
return return
end end
local n = #results
vim.notify(string.format("Updated %d plugin%s", n, n == 1 and "" or "s"), vim.log.levels.INFO)
local ok, snacks = pcall(require, "snacks") local ok, snacks = pcall(require, "snacks")
if ok and snacks.picker then if ok and snacks.picker then
local items = {} local items = {}
@@ -216,15 +160,6 @@ local function collect_and_show()
end end
end end
-- ── Completion detection ──────────────────────────────────────────────
local function on_complete()
write_stamp()
state.complete = true
progress_draw()
vim.defer_fn(collect_and_show, 400)
end
-- ── Main update ─────────────────────────────────────────────────────── -- ── Main update ───────────────────────────────────────────────────────
function M.update() function M.update()
@@ -243,36 +178,31 @@ function M.update()
return vim.notify("No active plugins", vim.log.levels.INFO) return vim.notify("No active plugins", vim.log.levels.INFO)
end end
state = { snapshot = snapshot, total = #names, changed = 0 } state = { snapshot = snapshot, changed = 0 }
progress_open()
local timer = vim.uv.new_timer() local timer = vim.uv.new_timer()
local au_id local au_id
local function reset_debounce() local function on_done()
timer:stop()
timer:start(
2000,
0,
vim.schedule_wrap(function()
pcall(vim.api.nvim_del_autocmd, au_id) pcall(vim.api.nvim_del_autocmd, au_id)
timer:close() timer:close()
on_complete() write_stamp()
end) collect_and_show()
)
end end
au_id = vim.api.nvim_create_autocmd("PackChanged", { au_id = vim.api.nvim_create_autocmd("PackChanged", {
callback = function() callback = function(ev)
if not state then if not state then
return pcall(vim.api.nvim_del_autocmd, au_id) return pcall(vim.api.nvim_del_autocmd, au_id)
end end
state.changed = state.changed + 1 state.changed = state.changed + 1
progress_draw() local name = ev.data and ev.data.spec and ev.data.spec.name or "plugin"
reset_debounce() vim.notify(string.format("Updated %s (%d)", name, state.changed), vim.log.levels.INFO)
timer:stop()
timer:start(2000, 0, vim.schedule_wrap(on_done))
end, end,
}) })
reset_debounce() timer:start(2000, 0, vim.schedule_wrap(on_done))
vim.pack.update(names, { force = true }) vim.pack.update(names, { force = true })
end end
@@ -281,7 +211,6 @@ end
function M.setup(opts) function M.setup(opts)
vim.g.tiny_packupdate_loaded = true vim.g.tiny_packupdate_loaded = true
cfg = vim.tbl_extend("force", cfg, opts or {}) cfg = vim.tbl_extend("force", cfg, opts or {})
vim.api.nvim_set_hl(0, "TinyPackProgress", { default = true, link = "DiagnosticOk" })
vim.api.nvim_create_user_command(cfg.command, M.update, { desc = "Update all plugins" }) vim.api.nvim_create_user_command(cfg.command, M.update, { desc = "Update all plugins" })
local interval = auto_intervals[cfg.auto] local interval = auto_intervals[cfg.auto]
if interval and os.time() - read_stamp() >= interval then if interval and os.time() - read_stamp() >= interval then