diff --git a/README.md b/README.md index 873c734..cbc5e98 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,11 @@ require('executor').setup({ failed = "✖ ", passed = "✓", }, + }, + callbacks = { + -- Called when a task completes so you can hook into the lifecycle. + on_complete = function(last_cmd, exit_code, stdout) + end } }) ``` diff --git a/doc/executor.txt b/doc/executor.txt index cd0d0c5..1c78c5b 100644 --- a/doc/executor.txt +++ b/doc/executor.txt @@ -253,6 +253,11 @@ the default options. failed = "✖ ", passed = "✓", }, + }, + callbacks = { + -- Called when a task completes so you can hook into the lifecycle. + on_complete = function(last_cmd, exit_code, stdout) + end } }) < diff --git a/lua/executor/executor.lua b/lua/executor/executor.lua index 623ce1c..86827f4 100644 --- a/lua/executor/executor.lua +++ b/lua/executor/executor.lua @@ -84,6 +84,10 @@ M._settings = { passed = "✓", }, }, + callbacks = { + ---@diagnostic disable-next-line: unused-local + on_complete = function(_cmd, _code, _stdout) end, + }, } M.configure = function(config) @@ -248,6 +252,7 @@ M._on_exit = function(_, exit_code) -- it. local output = Output.output_for_state(M._state) + if M._popup and M._popup.winid then Output.write_data(M._stored_task_command, M._popup.bufnr, M._settings.output_filter, output) end @@ -262,6 +267,8 @@ M._on_exit = function(_, exit_code) M._show_notification("✓ Task success!", true) end end + + M._settings.callbacks.on_complete(M._state.last_command, exit_code, output) -- Force the statusline to redraw. vim.api.nvim_exec([[let &stl=&stl]], false) end