From 063bc7faede7b9254aa95394f5e10d527f610798 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Sat, 14 Jun 2025 17:40:48 +0100 Subject: [PATCH 1/2] Add on_complete callback. Fixes #33. --- README.md | 5 +++++ lua/executor/executor.lua | 7 +++++++ 2 files changed, 12 insertions(+) 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/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 From 5fcceacd407fd99fe6405207e4c94ccb3e2a603a Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Sun, 15 Jun 2025 19:53:23 +0100 Subject: [PATCH 2/2] docs --- doc/executor.txt | 5 +++++ 1 file changed, 5 insertions(+) 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 } }) <