diff --git a/lua/noice/message/router.lua b/lua/noice/message/router.lua index c556d03..786f7c8 100644 --- a/lua/noice/message/router.lua +++ b/lua/noice/message/router.lua @@ -215,4 +215,22 @@ function M.update() M._updating = false end +function M.echo_pending() + local messages = Manager.get({ event = "msg_show" }, { sort = true }) + local chunks = {} + for _, message in ipairs(messages) do + for _, line in ipairs(message._lines) do + ---@param t NuiText + local chunk = vim.tbl_map(function(t) + return { t:content(), t.extmark.hl_group } + end, line._texts) + vim.list_extend(chunks, chunk) + end + end + chunks[#chunks + 1] = { "foobar", "Normal" } + -- vim.opt.cmdheight = 10 + -- vim.opt.more = false + vim.api.nvim_echo(chunks, true, {}) +end + return M diff --git a/lua/noice/ui/init.lua b/lua/noice/ui/init.lua index 7bc2c22..81b3d24 100644 --- a/lua/noice/ui/init.lua +++ b/lua/noice/ui/init.lua @@ -103,12 +103,17 @@ function M.enable() end stack_level = stack_level - 1 end) + +function M.redirect() + M.disable() + Router.echo_pending() + vim.schedule(M.enable) end function M.disable() if M._attached then - vim.ui_detach(Config.ns) M._attached = false + vim.ui_detach(Config.ns) end end diff --git a/lua/noice/util/hacks.lua b/lua/noice/util/hacks.lua index 7741bdb..8acd26d 100644 --- a/lua/noice/util/hacks.lua +++ b/lua/noice/util/hacks.lua @@ -145,7 +145,7 @@ end ---@see https://github.com/neovim/neovim/issues/20311 M.before_input = false function M.fix_input() - local function wrap(fn, skip) + local function wrap(fn, skip, redirect) return function(...) if skip and skip(...) then return fn(...) @@ -157,10 +157,20 @@ function M.fix_input() M.before_input = true Router.update() - M.hide_cursor() + if redirect then + require("noice.ui").redirect() + end + + if not redirect then + M.hide_cursor() + end + ---@type boolean, any local ok, ret = pcall(fn, ...) - M.show_cursor() + + if not redirect then + M.show_cursor() + end -- clear any message right after input Manager.clear({ event = "msg_show", kind = { "echo", "echomsg", "" } }) @@ -179,15 +189,18 @@ function M.fix_input() local getchar = vim.fn.getchar local getcharstr = vim.fn.getcharstr local inputlist = vim.fn.inputlist + -- local confirm = vim.fn.confirm vim.fn.getchar = wrap(vim.fn.getchar, skip) vim.fn.getcharstr = wrap(vim.fn.getcharstr, skip) - vim.fn.inputlist = wrap(vim.fn.inputlist) + vim.fn.inputlist = wrap(vim.fn.inputlist, nil) + -- vim.fn.confirm = wrap(vim.fn.confirm, nil) table.insert(M._disable, function() vim.fn.getchar = getchar vim.fn.getcharstr = getcharstr vim.fn.inputlist = inputlist + -- vim.fn.confirm = confirm end) end