diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-02-07 09:57:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-07 09:57:23 +0100 |
commit | 366528130e397a6173789072c08b9afa5efd0423 (patch) | |
tree | d41bd3f486d87842fa65108a072de465e2dee4bf | |
parent | 538361955d123d9c93387f7597303c0ef59c6825 (diff) | |
parent | 35a789278128bfe5d28e4c61ac7fa727042fd30a (diff) | |
download | rneovim-366528130e397a6173789072c08b9afa5efd0423.tar.gz rneovim-366528130e397a6173789072c08b9afa5efd0423.tar.bz2 rneovim-366528130e397a6173789072c08b9afa5efd0423.zip |
Merge #6713 'tests for :! output'
-rw-r--r-- | src/nvim/README.md | 6 | ||||
-rw-r--r-- | src/nvim/normal.c | 4 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 8 | ||||
-rw-r--r-- | src/nvim/os/time.c | 22 | ||||
-rw-r--r-- | src/nvim/ui.c | 7 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/eval/execute_spec.lua | 5 | ||||
-rw-r--r-- | test/functional/ui/output_spec.lua | 70 |
8 files changed, 100 insertions, 26 deletions
diff --git a/src/nvim/README.md b/src/nvim/README.md index 1ece92e44d..d668db0cdc 100644 --- a/src/nvim/README.md +++ b/src/nvim/README.md @@ -90,6 +90,12 @@ Record a Nvim terminal session and format it with `vterm-dump`: Then you can compare `bar` with another session, to debug TUI behavior. +### TUI redraw + +Set the 'writedelay' option to see where and when the UI is painted. + + :set writedelay=1 + ### Terminal reference - `man terminfo` diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 47044a6072..bca4a0f93e 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5031,8 +5031,8 @@ static void nv_right(cmdarg_T *cap) if ((!PAST_LINE && oneright() == false) || (PAST_LINE && *get_cursor_pos_ptr() == NUL) ) { - // <Space> wraps to next line if 'whichwrap' has 's'. - // 'l' wraps to next line if 'whichwrap' has 'l'. + // <Space> wraps to next line if 'whichwrap' has 's'. + // 'l' wraps to next line if 'whichwrap' has 'l'. // CURS_RIGHT wraps to next line if 'whichwrap' has '>'. if (((cap->cmdchar == ' ' && vim_strchr(p_ww, 's') != NULL) || (cap->cmdchar == 'l' && vim_strchr(p_ww, 'l') != NULL) diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 11e6a76939..5b3cb64a4d 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -576,14 +576,10 @@ static void read_input(DynamicBuffer *buf) if (len == l) { // Finished a line, add a NL, unless this line should not have one. - // FIXME need to make this more readable if (lnum != curbuf->b_op_end.lnum - || (!curbuf->b_p_bin - && curbuf->b_p_fixeol) + || (!curbuf->b_p_bin && curbuf->b_p_fixeol) || (lnum != curbuf->b_no_eol_lnum - && (lnum != - curbuf->b_ml.ml_line_count - || curbuf->b_p_eol))) { + && (lnum != curbuf->b_ml.ml_line_count || curbuf->b_p_eol))) { dynamic_buffer_ensure(buf, buf->len + 1); buf->data[buf->len++] = NL; } diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index c471352c02..290d421acc 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -38,33 +38,33 @@ uint64_t os_hrtime(void) return uv_hrtime(); } -/// Sleeps for a certain amount of milliseconds. +/// Sleeps for `ms` milliseconds. /// -/// @param milliseconds Number of milliseconds to sleep +/// @param ms Number of milliseconds to sleep /// @param ignoreinput If true, only SIGINT (CTRL-C) can interrupt. -void os_delay(uint64_t milliseconds, bool ignoreinput) +void os_delay(uint64_t ms, bool ignoreinput) { if (ignoreinput) { - if (milliseconds > INT_MAX) { - milliseconds = INT_MAX; + if (ms > INT_MAX) { + ms = INT_MAX; } - LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, (int)milliseconds, got_int); + LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, (int)ms, got_int); } else { - os_microdelay(milliseconds * 1000u, ignoreinput); + os_microdelay(ms * 1000u, ignoreinput); } } -/// Sleeps for a certain amount of microseconds. +/// Sleeps for `us` microseconds. /// -/// @param ms Number of microseconds to sleep. +/// @param us Number of microseconds to sleep. /// @param ignoreinput If true, ignore all input (including SIGINT/CTRL-C). /// If false, waiting is aborted on any input. -void os_microdelay(uint64_t ms, bool ignoreinput) +void os_microdelay(uint64_t us, bool ignoreinput) { uint64_t elapsed = 0u; uint64_t base = uv_hrtime(); // Convert microseconds to nanoseconds, or UINT64_MAX on overflow. - const uint64_t ns = (ms < UINT64_MAX / 1000u) ? ms * 1000u : UINT64_MAX; + const uint64_t ns = (us < UINT64_MAX / 1000u) ? us * 1000u : UINT64_MAX; uv_mutex_lock(&delay_mutex); diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 8aec923538..709a172449 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -453,6 +453,13 @@ void ui_puts(uint8_t *str) ui_linefeed(); } p += clen; + + if (p_wd) { // 'writedelay': flush & delay each time. + ui_flush(); + assert(p_wd >= 0 + && (sizeof(long) <= sizeof(uint64_t) || p_wd <= UINT64_MAX)); + os_delay((uint64_t)p_wd, false); + } } } diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 0a0cb2e91c..1faed4e9b1 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -11,11 +11,11 @@ local funcs = helpers.funcs local request = helpers.request local meth_pcall = helpers.meth_pcall local command = helpers.command +local iswin = helpers.iswin local intchar2lua = global_helpers.intchar2lua local format_string = global_helpers.format_string local mergedicts_copy = global_helpers.mergedicts_copy -local uname = global_helpers.uname describe('api', function() before_each(clear) @@ -101,7 +101,7 @@ describe('api', function() end) it('returns shell |:!| output', function() - local win_lf = (uname() == 'Windows' and '\r') or '' + local win_lf = iswin() and '\r' or '' eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]])) end) diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua index c866359520..183884a51e 100644 --- a/test/functional/eval/execute_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local global_helpers = require('test.helpers') local eq = helpers.eq local eval = helpers.eval local clear = helpers.clear @@ -10,7 +9,7 @@ local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') local command = helpers.command local feed = helpers.feed -local uname = global_helpers.uname +local iswin = helpers.iswin describe('execute()', function() before_each(clear) @@ -123,7 +122,7 @@ describe('execute()', function() -- This deviates from vim behavior, but is consistent -- with how nvim currently displays the output. it('does capture shell-command output', function() - local win_lf = (uname() == 'Windows' and '\13') or '' + local win_lf = iswin() and '\13' or '' eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo')) end) diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua index da3f474e08..c42c0b26c6 100644 --- a/test/functional/ui/output_spec.lua +++ b/test/functional/ui/output_spec.lua @@ -1,9 +1,14 @@ +local Screen = require('test.functional.ui.screen') local session = require('test.functional.helpers')(after_each) local child_session = require('test.functional.terminal.helpers') - -if session.pending_win32(pending) then return end +local eq = session.eq +local eval = session.eval +local feed = session.feed +local iswin = session.iswin describe("shell command :!", function() + if session.pending_win32(pending) then return end + local screen before_each(function() session.clear() @@ -66,3 +71,64 @@ describe("shell command :!", function() ]]) end) end) + +describe("shell command :!", function() + before_each(function() + session.clear() + end) + + it("cat a binary file #4142", function() + feed(":exe 'silent !cat '.shellescape(v:progpath)<CR>") + eq(2, eval('1+1')) -- Still alive? + end) + + it([[display \x08 char #4142]], function() + feed(":silent !echo \08<CR>") + eq(2, eval('1+1')) -- Still alive? + end) + + it([[handles control codes]], function() + if iswin() then + pending('missing printf', function() end) + return + end + local screen = Screen.new(50, 4) + screen:attach() + -- Print TAB chars. #2958 + feed([[:!printf '1\t2\t3'<CR>]]) + screen:expect([[ + ~ | + :!printf '1\t2\t3' | + 1 2 3 | + Press ENTER or type command to continue^ | + ]]) + feed([[<CR>]]) + -- Print BELL control code. #4338 + feed([[:!printf '\x07\x07\x07\x07text'<CR>]]) + screen:expect([[ + ~ | + :!printf '\x07\x07\x07\x07text' | + ^G^G^G^Gtext | + Press ENTER or type command to continue^ | + ]]) + feed([[<CR>]]) + -- Print BS control code. + feed([[:echo system('printf ''\x08\n''')<CR>]]) + screen:expect([[ + ~ | + ^H | + | + Press ENTER or type command to continue^ | + ]]) + feed([[<CR>]]) + -- Print LF control code. + feed([[:!printf '\n'<CR>]]) + screen:expect([[ + :!printf '\n' | + | + | + Press ENTER or type command to continue^ | + ]]) + feed([[<CR>]]) + end) +end) |