From cb4e8c25e474ebf5d0eb47f5bd5088645a6f2f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Sun, 17 Jul 2022 18:53:15 +0100 Subject: [PATCH] feat(output): auto-exit terminal mode See #67 --- lua/neotest/async.lua | 5 +++++ lua/neotest/consumers/output.lua | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lua/neotest/async.lua b/lua/neotest/async.lua index 57f52a47..becbed23 100644 --- a/lua/neotest/async.lua +++ b/lua/neotest/async.lua @@ -19,6 +19,11 @@ local async_wrapper = { api = proxy_vim("api"), fn = proxy_vim("fn"), } +if false then + -- For type checking + async_wrapper.api = vim.api + async_wrapper.fn = vim.fn +end setmetatable(async_wrapper, { __index = function(_, k) diff --git a/lua/neotest/consumers/output.lua b/lua/neotest/consumers/output.lua index f8c80c5a..d1c02ceb 100644 --- a/lua/neotest/consumers/output.lua +++ b/lua/neotest/consumers/output.lua @@ -13,6 +13,17 @@ local function open_output(result, opts) local dos_newlines = string.find(output, "\r\n") ~= nil async.api.nvim_chan_send(chan, dos_newlines and output or output:gsub("\n", "\r\n")) async.util.sleep(10) -- Wait for chan to send + async.api.nvim_create_autocmd("TermEnter", { + buffer = buf, + callback = function() + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes("", true, true, true), + "n", + false + ) + end, + }) + local lines = async.api.nvim_buf_get_lines(buf, 0, -1, false) local width, height = 80, #lines for i, line in ipairs(lines) do