neovim/test/functional/ui/output_spec.lua
Justin M. Keyes 97204e1cef os/shell: Throttle :! output, pulse "..." message.
Periodically skip :! spam. This is a "cheat" that works for all UIs and greatly
improves responsiveness when :! spams MB or GB of output:
    :!yes
    :!while true; do date; done
    :!git grep ''
    :grep -r '' *

After ~10KB of data is seen from a single :! invocation, output will be skipped
for ~1s and three dots "..." will pulse in the bottom-left. Thereafter the
behavior alternates at every:
    * 10KB received
    * ~1s throttled

This also avoids out-of-memory which could happen with large :! outputs.

Note: This commit does not change the behavior of execute(':!foo').
      execute(':!foo') returns the string ':!foo^M', it captures *only* Vim
      messages, *not* shell command output. Vim behaves the same way.
      Use system('foo') for capturing shell command output.

Closes #1234

Helped-by: oni-link <knil.ino@gmail.com>
2016-12-09 18:51:17 +01:00

51 lines
2.0 KiB
Lua

local session = require('test.functional.helpers')(after_each)
local child_session = require('test.functional.terminal.helpers')
local Screen = require('test.functional.ui.screen')
if session.pending_win32(pending) then return end
describe("shell command :!", function()
local screen
before_each(function()
session.clear()
screen = child_session.screen_setup(0, '["'..session.nvim_prog..
'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile"]')
screen:expect([[
{1: } |
{4:~ }|
{4:~ }|
{4:~ }|
{5:[No Name] }|
|
{3:-- TERMINAL --} |
]])
end)
after_each(function()
child_session.feed_data("\3") -- Ctrl-C
screen:detach()
end)
it("displays output even without LF/EOF. #4646 #4569 #3772", function()
-- NOTE: We use a child nvim (within a :term buffer)
-- to avoid triggering a UI flush.
child_session.feed_data(":!printf foo; sleep 200\n")
screen:expect([[
{4:~ }|
{4:~ }|
{5:[No Name] }|
:!printf foo; sleep 200 |
|
foo |
{3:-- TERMINAL --} |
]])
end)
it("throttles shell-command output greater than ~20KB", function()
child_session.feed_data(
":!for i in $(seq 2 3000); do echo XXXXXXXXXX; done\n")
-- If a line with only a dot "." appears, then throttling was triggered.
screen:expect("\n.", nil, nil, nil, true)
end)
end)