diff --git a/doc/neotest.txt b/doc/neotest.txt index 19c3f100..0d05dcce 100644 --- a/doc/neotest.txt +++ b/doc/neotest.txt @@ -446,6 +446,14 @@ Toggle the output panel lua require("neotest").output_panel.toggle() < + *neotest.output_panel.clear()* +`clear`() + +Clears the output panel +>vim + lua require("neotest").output_panel.clear() +< + ============================================================================== neotest.run *neotest.run* diff --git a/lua/neotest/consumers/output_panel/init.lua b/lua/neotest/consumers/output_panel/init.lua index e58055ea..a65949c2 100644 --- a/lua/neotest/consumers/output_panel/init.lua +++ b/lua/neotest/consumers/output_panel/init.lua @@ -83,6 +83,16 @@ function neotest.output_panel.toggle() end end +--- Clears the output panel +--- >vim +--- lua require("neotest").output_panel.clear() +--- < +function neotest.output_panel.clear() + nio.api.nvim_buf_set_option(panel.win:buffer(), "modifiable", true) + nio.api.nvim_buf_set_lines(panel.win:buffer(), 0, -1, false, {}) + nio.api.nvim_buf_set_option(panel.win:buffer(), "modifiable", false) +end + neotest.output_panel = setmetatable(neotest.output_panel, { __call = function(_, client) init(client) diff --git a/plugin/neotest.lua b/plugin/neotest.lua index 2463f001..33fe23ab 100644 --- a/plugin/neotest.lua +++ b/plugin/neotest.lua @@ -16,6 +16,7 @@ local cmd_completion_store = { "open", "close", "toggle", + "clear", }, run = { "file", @@ -78,6 +79,9 @@ commands = { toggle = function() require("neotest").output_panel.toggle() end, + clear = function() + require("neotest").output_panel.clear() + end, }, run = { function(params)