feat(overseer): keep task output visible after completion and add manual close keys

This commit is contained in:
Prad Nukala committed 2026-09-21 16:36:40 -04:00
1 parent d663a571d3
commit c34b24d91d
1 file changed
+25 -14
+25 -14
View File
@@ -1,7 +1,9 @@
--- Overseer component: show task output in a Snacks window docked to the --- Overseer component: show task output in a Snacks window docked to the
--- bottom of the editor, toggleterm-style: the window is focused and dropped --- bottom of the editor, toggleterm-style: the window is focused and dropped
--- into terminal mode when the task starts (and whenever the buffer is --- into terminal mode when the task starts (and whenever the buffer is
--- re-entered), and closes itself when the task exits. --- re-entered). Output stays on screen after the task exits; <CR> or q then
--- close the window (while running, keys still go to the process; q in
--- normal mode always closes).
--- ---
--- The task's own terminal buffer (owned by the jobstart strategy, so exit --- The task's own terminal buffer (owned by the jobstart strategy, so exit
--- status / output parsing keep working) is placed in a single shared --- status / output parsing keep working) is placed in a single shared
@@ -51,7 +53,7 @@ local function show(bufnr, params)
backdrop = false, backdrop = false,
fixbuf = false, fixbuf = false,
wo = { number = false, relativenumber = false, signcolumn = "no", winbar = "", wrap = true }, wo = { number = false, relativenumber = false, signcolumn = "no", winbar = "", wrap = true },
keys = { q = "close" }, keys = {},
} }
end end
if params.auto_insert then if params.auto_insert then
@@ -85,27 +87,36 @@ return {
type = "boolean", type = "boolean",
default = true, default = true,
}, },
auto_close = {
desc = "Close the output window when the task exits",
type = "boolean",
default = true,
},
}, },
constructor = function(params) constructor = function(params)
--- @param task overseer.Task --- @param bufnr integer
local function close_if_showing(task) local function close_win(bufnr)
local bufnr = task:get_bufnr() if showing(bufnr) then win:close() end
if bufnr and showing(bufnr) then win:close() end
end end
return { return {
on_start = function(_, task) on_start = function(_, task)
local bufnr = task:get_bufnr() local bufnr = task:get_bufnr()
if bufnr then show(bufnr, params) end if not bufnr then return end
-- a restart with preserve_output reuses the buffer: hand the keys
-- back to the process until the task completes again
pcall(vim.keymap.del, "t", "<CR>", { buffer = bufnr })
pcall(vim.keymap.del, "t", "q", { buffer = bufnr })
pcall(vim.keymap.del, "n", "<CR>", { buffer = bufnr })
vim.keymap.set("n", "q", function() close_win(bufnr) end, { buffer = bufnr, nowait = true, desc = "Close task output" })
show(bufnr, params)
end, end,
on_complete = function(_, task) on_complete = function(_, task)
if params.auto_close then close_if_showing(task) end local bufnr = task:get_bufnr()
if not bufnr then return end
local function close() close_win(bufnr) end
local opts = { buffer = bufnr, nowait = true, desc = "Close task output" }
vim.keymap.set({ "t", "n" }, "<CR>", close, opts)
vim.keymap.set("t", "q", close, opts)
end,
on_dispose = function(_, task)
local bufnr = task:get_bufnr()
if bufnr then close_win(bufnr) end
end, end,
on_dispose = function(_, task) close_if_showing(task) end,
} }
end, end,
} }