fix(extui): route interactive messages to more-window (#33885)

Problem:  Extui does not route messages emitted as a result of a typed
          command to the "more" window.
          Command message leading shell messages is missing a kind.
          Messages not routed to 'cmdheight' area after it was 0.
Solution: Route messages that were emitted in the same event loop as an
          entered command to the "more" window. Also append multiple
          messages in an already open more-window.
          Assign it the `shell_cmd` kind.
          Change message position when 'cmdheight' changes from 0.
This commit is contained in:
luukvbaal
2025-05-09 12:17:26 +02:00
committed by GitHub
parent 3121e02ae0
commit 7e787f6a4f
6 changed files with 40 additions and 19 deletions

View File

@@ -219,8 +219,9 @@ function M.show_msg(tar, content, replace_last, more)
local srow, scol = row, col
-- Split at newline and concatenate first and last message chunks.
for str in (chunk[2] .. '\0'):gmatch('.-[\n%z]') do
local idx = i > 1 and row == srow and 0 or 1
lines[#lines + idx] = idx > 0 and str:sub(1, -2) or lines[#lines] .. str:sub(1, -2)
local idx = #lines + (i > 1 and row == srow and 0 or 1)
-- Filter out NL, CRs and appended NUL. TODO: actually handle carriage return?
lines[idx] = (lines[idx] or '') .. str:gsub('[\n\r%z]', '')
col = #lines[#lines]
row = row + (str:sub(-1) == '\0' and 0 or 1)
if tar == 'box' then
@@ -279,6 +280,7 @@ function M.show_msg(tar, content, replace_last, more)
end
end
local append_more = 0
local replace_bufwrite = false
--- Route the message to the appropriate sink.
---
@@ -302,7 +304,7 @@ function M.msg_show(kind, content)
elseif kind == 'return_prompt' then
-- Bypass hit enter prompt.
vim.api.nvim_feedkeys(vim.keycode('<CR>'), 'n', false)
elseif kind == 'verbose' then
elseif kind == 'verbose' and append_more == 0 then
-- Verbose messages are sent too often to be meaningful in the cmdline:
-- always route to box regardless of cfg.msg.pos.
M.show_msg('box', content, false)
@@ -323,7 +325,9 @@ function M.msg_show(kind, content)
M.virt.last[M.virt.idx.search][1] = nil
end
M.show_msg(tar, content, replace_bufwrite, kind == 'list_cmd')
-- Messages sent as a result of a typed command should be routed to the more window.
local more = ext.cmd.level >= 0 or kind == 'list_cmd'
M.show_msg(tar, content, replace_bufwrite, more)
-- Replace message for every second bufwrite message.
replace_bufwrite = not replace_bufwrite and kind == 'bufwrite'
end
@@ -367,9 +371,14 @@ function M.msg_history_show(entries)
return
end
api.nvim_buf_set_lines(ext.bufs.more, 0, -1, false, {})
-- Appending messages while 'more' window is open.
append_more = entries[1][1] == 'spill' and append_more + 1 or 0
if append_more < 2 then
api.nvim_buf_set_lines(ext.bufs.more, 0, -1, false, {})
end
for i, entry in ipairs(entries) do
M.show_msg('more', entry[2], i == 1)
M.show_msg('more', entry[2], i == 1 and append_more < 2)
end
M.set_pos('more')
@@ -402,6 +411,7 @@ function M.set_pos(type)
if api.nvim_win_is_valid(win) then
api.nvim_win_set_config(win, { hide = true })
end
append_more = 0
end,
desc = 'Hide inactive more window.',
})