Skip to content

Commit

Permalink
terminal: flush vterm output buffer on pty output #8486
Browse files Browse the repository at this point in the history
Fixes #4151

libvterm uses an "output buffer" for terminal reporting
(e.g. \e[6n to report cursor position)
Flush it in on_channel_output() not just terminal_send_key()

See also this line from pangoterm:
https://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/607/pangoterm.c#L2159
  • Loading branch information
lincheney authored and justinmk committed Jun 8, 2018
1 parent db68d1d commit 451c48a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/nvim/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf,
// process_channel_event will modify the read buffer(convert NULs into NLs)
if (chan->term) {
terminal_receive(chan->term, ptr, count);
terminal_flush_output(chan->term);
}

rbuffer_consumed(buf, count);
Expand Down
13 changes: 9 additions & 4 deletions src/nvim/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ void terminal_send(Terminal *term, char *data, size_t size)
term->opts.write_cb(data, size, term->opts.data);
}

void terminal_flush_output(Terminal *term)
{
size_t len = vterm_output_read(term->vt, term->textbuf,
sizeof(term->textbuf));
terminal_send(term, term->textbuf, len);
}

void terminal_send_key(Terminal *term, int c)
{
VTermModifier mod = VTERM_MOD_NONE;
Expand All @@ -545,9 +552,7 @@ void terminal_send_key(Terminal *term, int c)
vterm_keyboard_unichar(term->vt, (uint32_t)c, mod);
}

size_t len = vterm_output_read(term->vt, term->textbuf,
sizeof(term->textbuf));
terminal_send(term, term->textbuf, (size_t)len);
terminal_flush_output(term);
}

void terminal_receive(Terminal *term, char *data, size_t len)
Expand Down Expand Up @@ -982,7 +987,7 @@ static bool send_mouse_event(Terminal *term, int c)

mouse_action(term, button, row, col, drag, 0);
size_t len = vterm_output_read(term->vt, term->textbuf,
sizeof(term->textbuf));
sizeof(term->textbuf));
terminal_send(term, term->textbuf, (size_t)len);
return false;
}
Expand Down
10 changes: 10 additions & 0 deletions test/functional/terminal/ex_terminal_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ describe(':terminal', function()
]])
end)

it("reads output buffer on terminal reporting #4151", function()
if helpers.pending_win32(pending) then return end
if iswin() then
feed_command([[terminal powershell -NoProfile -NoLogo -Command Write-Host -NoNewline "\"$([char]27)[6n\""; Start-Sleep -Milliseconds 500 ]])
else
feed_command([[terminal printf '\e[6n'; sleep 0.5 ]])
end
screen:expect('%^%[%[1;1R', nil, nil, nil, true)
end)

it("in normal-mode :split does not move cursor", function()
if iswin() then
feed_command([[terminal for /L \\%I in (1,0,2) do ( echo foo & ping -w 100 -n 1 127.0.0.1 > nul )]])
Expand Down

0 comments on commit 451c48a

Please sign in to comment.