Skip to content

Commit

Permalink
feat(ui): added hybrid messages functionality, but not needed for now
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 14, 2023
1 parent b415afa commit addc0a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
18 changes: 18 additions & 0 deletions lua/noice/message/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion lua/noice/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 17 additions & 4 deletions lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)
Expand All @@ -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", "" } })
Expand All @@ -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

Expand Down

0 comments on commit addc0a2

Please sign in to comment.