Skip to content

Commit

Permalink
fix(--headless): do not block on press-enter prompts when no UI
Browse files Browse the repository at this point in the history
This commit fixes neovim#9358, where emitting multiple messages with 'echo' or
a single one with 'echom' or 'echoerr' would result in a press-enter
prompt that couldn't be dismissed by pressing enter.

This requires adapting a few tests to spawn a UI before testing whether
press-enter prompts are blocking.

It also fixes neovim#11718, as when combined with neovim#15910 it enables making
sure that neovim never blocks and emits messages on startup.
  • Loading branch information
glacambre committed Feb 5, 2022
1 parent 806a7c9 commit 1c4c746
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/nvim/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,10 @@ void wait_return(int redraw)
return;
}

if (headless_mode && !ui_active()) {
return;
}

/*
* When inside vgetc(), we can't wait for a typed character at all.
* With the global command (and some others) we only need one return at
Expand Down
15 changes: 15 additions & 0 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ describe('API', function()

describe('nvim_command_output', function()
it('does not induce hit-enter prompt', function()
nvim("ui_attach", 80, 20, {})
-- Induce a hit-enter prompt use nvim_input (non-blocking).
nvim('command', 'set cmdheight=1')
nvim('input', [[:echo "hi\nhi2"<CR>]])
Expand Down Expand Up @@ -1093,7 +1094,20 @@ describe('API', function()
eq({mode='n', blocking=false}, nvim("get_mode"))
end)

it("during press-enter prompt without UI returns blocking=false", function()
eq({mode='n', blocking=false}, nvim("get_mode"))
command("echom 'msg1'")
command("echom 'msg2'")
command("echom 'msg3'")
command("echom 'msg4'")
command("echom 'msg5'")
eq({mode='n', blocking=false}, nvim("get_mode"))
nvim("input", ":messages<CR>")
eq({mode='n', blocking=false}, nvim("get_mode"))
end)

it("during press-enter prompt returns blocking=true", function()
nvim("ui_attach", 80, 20, {})
eq({mode='n', blocking=false}, nvim("get_mode"))
command("echom 'msg1'")
command("echom 'msg2'")
Expand All @@ -1117,6 +1131,7 @@ describe('API', function()

-- TODO: bug #6247#issuecomment-286403810
it("batched with input", function()
nvim("ui_attach", 80, 20, {})
eq({mode='n', blocking=false}, nvim("get_mode"))
command("echom 'msg1'")
command("echom 'msg2'")
Expand Down
8 changes: 4 additions & 4 deletions test/functional/core/channels_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ describe('channels', function()
eq({"notification", "stdout", {id, {"[1, ['hola'], 'stdin']"}}}, next_msg())

command("call chanclose(id, 'stdin')")
expect_twostreams({{"notification", "stdout", {id, {"[1, [''], 'stdin']"}}},
{'notification', 'stdout', {id, {''}}}},
{{"notification", "stderr", {id, {"*dies*"}}},
{'notification', 'stderr', {id, {''}}}})
expect_twostreams({{"notification", "stderr", {id, {"*dies*"}}},
{'notification', 'stderr', {id, {''}}}},
{{"notification", "stdout", {id, {"[1, [''], 'stdin']"}}},
{'notification', 'stdout', {id, {''}}}})
eq({"notification", "exit", {3,0}}, next_msg())
end)

Expand Down

0 comments on commit 1c4c746

Please sign in to comment.