From 9cdbbd49825561d642705990a2704b2241cf0584 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 17 Apr 2017 11:32:14 +0200 Subject: ui: support more cursor shape modes throttle unneccessary cursor shape events --- src/nvim/api/ui.c | 23 +++++++++---------- src/nvim/cursor_shape.c | 35 ++++++++++++++++++++++++++++- src/nvim/cursor_shape.h | 3 ++- src/nvim/ex_getln.c | 16 +++++++++++++ src/nvim/mouse.c | 1 + src/nvim/tui/tui.c | 60 +++++++++++++------------------------------------ src/nvim/ui.c | 31 +++++++++---------------- src/nvim/ui.h | 2 +- src/nvim/ui_bridge.c | 4 ++-- 9 files changed, 93 insertions(+), 82 deletions(-) diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index de60339e5f..0053050717 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -266,19 +266,14 @@ static void remote_ui_mouse_off(UI *ui) push_call(ui, "mouse_off", args); } -static void remote_ui_mode_change(UI *ui, int mode) +static void remote_ui_mode_change(UI *ui, int mode_idx) { Array args = ARRAY_DICT_INIT; - if (mode == INSERT) { - ADD(args, STRING_OBJ(cstr_to_string("insert"))); - } else if (mode == REPLACE) { - ADD(args, STRING_OBJ(cstr_to_string("replace"))); - } else if (mode == CMDLINE) { - ADD(args, STRING_OBJ(cstr_to_string("cmdline"))); - } else { - assert(mode == NORMAL); - ADD(args, STRING_OBJ(cstr_to_string("normal"))); - } + + char *full_name = shape_table[mode_idx].full_name; + ADD(args, STRING_OBJ(cstr_to_string(full_name))); + + ADD(args, INTEGER_OBJ(mode_idx)); push_call(ui, "mode_change", args); } @@ -393,8 +388,10 @@ static void remote_ui_update_sp(UI *ui, int sp) static void remote_ui_flush(UI *ui) { UIData *data = ui->data; - channel_send_event(data->channel_id, "redraw", data->buffer); - data->buffer = (Array)ARRAY_DICT_INIT; + if (data->buffer.size > 0) { + channel_send_event(data->channel_id, "redraw", data->buffer); + data->buffer = (Array)ARRAY_DICT_INIT; + } } static void remote_ui_suspend(UI *ui) diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 34ee53bf75..57dc241c54 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -11,7 +11,7 @@ #include "nvim/ui.h" /// Handling of cursor and mouse pointer shapes in various modes. -static cursorentry_T shape_table[SHAPE_IDX_COUNT] = +cursorentry_T shape_table[SHAPE_IDX_COUNT] = { // Values are set by 'guicursor' and 'mouseshape'. // Adjust the SHAPE_IDX_ defines when changing this! @@ -63,6 +63,7 @@ Dictionary cursor_shape_dict(void) PUT(dic, "id_lm", INTEGER_OBJ(cur->id_lm)); } PUT(dic, "short_name", STRING_OBJ(cstr_to_string(cur->name))); + PUT(dic, "mode_idx", INTEGER_OBJ(i)); PUT(all, cur->full_name, DICTIONARY_OBJ(dic)); } @@ -260,3 +261,35 @@ int cursor_mode_str2int(const char *mode) return -1; } + +/// Return the index into shape_table[] for the current mode. +int cursor_get_mode_idx(void) +{ + if (State == SHOWMATCH) { + return SHAPE_IDX_SM; + } else if (State & VREPLACE_FLAG) { + return SHAPE_IDX_R; + } else if (State & REPLACE_FLAG) { + return SHAPE_IDX_R; + } else if (State & INSERT) { + return SHAPE_IDX_I; + } else if (State & CMDLINE) { + if (cmdline_at_end()) { + return SHAPE_IDX_C; + } else if (cmdline_overstrike()) { + return SHAPE_IDX_CR; + } else { + return SHAPE_IDX_CI; + } + } else if (finish_op) { + return SHAPE_IDX_O; + } else if (VIsual_active) { + if (*p_sel == 'e') { + return SHAPE_IDX_VE; + } else { + return SHAPE_IDX_V; + } + } else { + return SHAPE_IDX_N; + } +} diff --git a/src/nvim/cursor_shape.h b/src/nvim/cursor_shape.h index 7cf65cba3c..2c466603f0 100644 --- a/src/nvim/cursor_shape.h +++ b/src/nvim/cursor_shape.h @@ -25,7 +25,7 @@ SHAPE_IDX_MORE = 14, ///< Hit-return or More SHAPE_IDX_MOREL = 15, ///< Hit-return or More in last line SHAPE_IDX_SM = 16, ///< showing matching paren SHAPE_IDX_COUNT = 17 -} MouseMode; +} ModeShape; typedef enum { SHAPE_BLOCK = 0, ///< block cursor @@ -53,6 +53,7 @@ typedef struct cursor_entry { char used_for; ///< SHAPE_MOUSE and/or SHAPE_CURSOR } cursorentry_T; +extern cursorentry_T shape_table[SHAPE_IDX_COUNT]; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "cursor_shape.h.generated.h" diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0b6036ace9..5d228e7492 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -351,6 +351,7 @@ static int command_line_check(VimState *state) quit_more = false; // reset after CTRL-D which had a more-prompt cursorcmd(); // set the cursor on the right spot + ui_cursor_shape(); return 1; } @@ -2092,6 +2093,18 @@ redraw: return (char_u *)line_ga.ga_data; } +bool cmdline_overstrike(void) +{ + return ccline.overstrike; +} + + +/// Return true if the cursor is at the end of the cmdline. +bool cmdline_at_end(void) +{ + return (ccline.cmdpos >= ccline.cmdlen); +} + /* * Allocate a new command line buffer. * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. @@ -2262,6 +2275,7 @@ void putcmdline(int c, int shift) draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); msg_no_more = FALSE; cursorcmd(); + ui_cursor_shape(); } /* @@ -2281,6 +2295,7 @@ void unputcmdline(void) draw_cmdline(ccline.cmdpos, 1); msg_no_more = FALSE; cursorcmd(); + ui_cursor_shape(); } /* @@ -2598,6 +2613,7 @@ void redrawcmdline(void) compute_cmdrow(); redrawcmd(); cursorcmd(); + ui_cursor_shape(); } static void redrawcmdprompt(void) diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 2ebe199f47..0029f364da 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -456,6 +456,7 @@ void setmouse(void) { int checkfor; + ui_cursor_shape(); /* be quick when mouse is off */ if (*p_mouse == NUL) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index f34f5f1bc4..3498e8f4e7 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -73,7 +73,7 @@ typedef struct { bool busy; cursorentry_T cursor_shapes[SHAPE_IDX_COUNT]; HlAttrs print_attrs; - int showing_mode; + ModeShape showing_mode; struct { int enable_mouse, disable_mouse; int enable_bracketed_paste, disable_bracketed_paste; @@ -131,7 +131,7 @@ static void terminfo_start(UI *ui) data->can_use_terminal_scroll = true; data->bufpos = 0; data->bufsize = sizeof(data->buf) - CNORM_COMMAND_MAX_SIZE; - data->showing_mode = 0; + data->showing_mode = SHAPE_IDX_N; data->unibi_ext.enable_mouse = -1; data->unibi_ext.disable_mouse = -1; data->unibi_ext.set_cursor_color = -1; @@ -173,7 +173,7 @@ static void terminfo_stop(UI *ui) { TUIData *data = ui->data; // Destroy output stuff - tui_mode_change(ui, NORMAL); + tui_mode_change(ui, SHAPE_IDX_N); tui_mouse_off(ui); unibi_out(ui, unibi_exit_attribute_mode); // cursor should be set to normal before exiting alternate screen @@ -451,7 +451,7 @@ CursorShape tui_cursor_decode_shape(const char *shape_str) return shape; } -static cursorentry_T decode_cursor_entry(Dictionary args) +static cursorentry_T decode_cursor_entry(Dictionary args, int *mode_idx) { cursorentry_T r; @@ -467,6 +467,8 @@ static cursorentry_T decode_cursor_entry(Dictionary args) r.blinkoff = (int)value.data.integer; } else if (strequal(key, "hl_id")) { r.id = (int)value.data.integer; + } else if (strequal(key, "mode_idx")) { + *mode_idx = (int)value.data.integer; } } return r; @@ -484,15 +486,15 @@ static void tui_cursor_style_set(UI *ui, bool enabled, Dictionary args) // Keys: as defined by `shape_table`. for (size_t i = 0; i < args.size; i++) { char *mode_name = args.items[i].key.data; - const int mode_id = cursor_mode_str2int(mode_name); - assert(mode_id >= 0); - cursorentry_T r = decode_cursor_entry(args.items[i].value.data.dictionary); + int mode_idx; + cursorentry_T r = decode_cursor_entry(args.items[i].value.data.dictionary, + &mode_idx); + assert(mode_idx >= 0); r.full_name = mode_name; - data->cursor_shapes[mode_id] = r; + data->cursor_shapes[mode_idx] = r; } - MouseMode cursor_mode = tui_mode2cursor(data->showing_mode); - tui_set_cursor(ui, cursor_mode); + tui_set_mode(ui, data->showing_mode); } static void tui_update_menu(UI *ui) @@ -529,7 +531,7 @@ static void tui_mouse_off(UI *ui) } /// @param mode one of SHAPE_XXX -static void tui_set_cursor(UI *ui, MouseMode mode) +static void tui_set_mode(UI *ui, ModeShape mode) { if (!cursor_style_enabled) { return; @@ -584,42 +586,12 @@ static void tui_set_cursor(UI *ui, MouseMode mode) } } -/// Returns cursor mode from edit mode -static MouseMode tui_mode2cursor(int mode) -{ - switch (mode) { - case INSERT: return SHAPE_IDX_I; - case CMDLINE: return SHAPE_IDX_C; - case REPLACE: return SHAPE_IDX_R; - case NORMAL: - default: return SHAPE_IDX_N; - } -} - /// @param mode editor mode -static void tui_mode_change(UI *ui, int mode) +static void tui_mode_change(UI *ui, int mode_idx) { TUIData *data = ui->data; - - if (mode == INSERT) { - if (data->showing_mode != INSERT) { - tui_set_cursor(ui, SHAPE_IDX_I); - } - } else if (mode == CMDLINE) { - if (data->showing_mode != CMDLINE) { - tui_set_cursor(ui, SHAPE_IDX_C); - } - } else if (mode == REPLACE) { - if (data->showing_mode != REPLACE) { - tui_set_cursor(ui, SHAPE_IDX_R); - } - } else { - assert(mode == NORMAL); - if (data->showing_mode != NORMAL) { - tui_set_cursor(ui, SHAPE_IDX_N); - } - } - data->showing_mode = mode; + tui_set_mode(ui, (ModeShape)mode_idx); + data->showing_mode = (ModeShape)mode_idx; } static void tui_set_scroll_region(UI *ui, int top, int bot, int left, diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 28f71b7ef2..8c5e579301 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -53,6 +53,7 @@ static int current_attr_code = 0; static bool pending_cursor_update = false; static int busy = 0; static int height, width; +static int old_mode_idx = -1; // UI_CALL invokes a function on all registered UI instances. The functions can // have 0-5 arguments (configurable by SELECT_NTH). @@ -150,12 +151,6 @@ void ui_event(char *name, Array args) } } -// May update the shape of the cursor. -void ui_cursor_shape(void) -{ - ui_mode_change(); -} - void ui_refresh(void) { if (!ui_active()) { @@ -181,6 +176,8 @@ void ui_refresh(void) screen_resize(width, height); pum_set_external(pum_external); ui_cursor_style_set(); + old_mode_idx = -1; + ui_cursor_shape(); } static void ui_refresh_event(void **argv) @@ -541,25 +538,19 @@ static void flush_cursor_update(void) } } -// Notify that the current mode has changed. Can be used to change cursor -// shape, for example. -static void ui_mode_change(void) +/// Check if current mode has changed. +/// May update the shape of the cursor. +void ui_cursor_shape(void) { - int mode; if (!full_screen) { return; } - // Get a simple UI mode out of State. - if ((State & REPLACE) == REPLACE) { - mode = REPLACE; - } else if (State & INSERT) { - mode = INSERT; - } else if (State & CMDLINE) { - mode = CMDLINE; - } else { - mode = NORMAL; + int mode_idx = cursor_get_mode_idx(); + + if (old_mode_idx != mode_idx) { + old_mode_idx = mode_idx; + UI_CALL(mode_change, mode_idx); } - UI_CALL(mode_change, mode); conceal_check_cursur_line(); } diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 8ffc5a45a6..d63ceb106c 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -28,7 +28,7 @@ struct ui_t { void (*busy_stop)(UI *ui); void (*mouse_on)(UI *ui); void (*mouse_off)(UI *ui); - void (*mode_change)(UI *ui, int mode); + void (*mode_change)(UI *ui, int mode_idx); void (*set_scroll_region)(UI *ui, int top, int bot, int left, int right); void (*scroll)(UI *ui, int count); void (*highlight_set)(UI *ui, HlAttrs attrs); diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index 9f780663ac..59942fb2cb 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -249,9 +249,9 @@ static void ui_bridge_mouse_off_event(void **argv) ui->mouse_off(ui); } -static void ui_bridge_mode_change(UI *b, int mode) +static void ui_bridge_mode_change(UI *b, int mode_idx) { - UI_CALL(b, mode_change, 2, b, INT2PTR(mode)); + UI_CALL(b, mode_change, 2, b, INT2PTR(mode_idx)); } static void ui_bridge_mode_change_event(void **argv) { -- cgit From 2c5751b9b2b22b8519aeda82088fe4525f2bd713 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 17 Apr 2017 13:32:22 +0200 Subject: ui: add tests for new cursor shape modes --- test/functional/terminal/ex_terminal_spec.lua | 2 +- test/functional/ui/cursor_spec.lua | 17 ++ test/functional/ui/mode_spec.lua | 227 ++++++++++++++++++++++++++ test/functional/ui/screen.lua | 5 +- test/functional/ui/screen_basic_spec.lua | 113 ------------- 5 files changed, 247 insertions(+), 117 deletions(-) create mode 100644 test/functional/ui/mode_spec.lua diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 154374cda9..1ed63adcfb 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -26,7 +26,7 @@ describe(':terminal', function() feed_command([[terminal while true; do echo X; done]]) helpers.feed([[]]) wait() - helpers.sleep(10) -- Let some terminal activity happen. + screen.sleep(10) -- Let some terminal activity happen. feed_command("messages") screen:expect([[ msg1 | diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 02e9422781..e4c1b17ef3 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -20,9 +20,11 @@ describe('ui/cursor', function() it("'guicursor' is published as a UI event", function() local expected_cursor_style = { cmdline_hover = { + mode_idx = 9, mouse_shape = 0, short_name = 'e' }, cmdline_insert = { + mode_idx = 5, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -33,6 +35,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'ci' }, cmdline_normal = { + mode_idx = 4, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -43,6 +46,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'c' }, cmdline_replace = { + mode_idx = 6, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -53,6 +57,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'cr' }, insert = { + mode_idx = 2, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -63,12 +68,15 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'i' }, more = { + mode_idx = 14, mouse_shape = 0, short_name = 'm' }, more_lastline = { + mode_idx = 15, mouse_shape = 0, short_name = 'ml' }, normal = { + mode_idx = 0, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -79,6 +87,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'n' }, operator = { + mode_idx = 7, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -89,6 +98,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'o' }, replace = { + mode_idx = 3, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -99,6 +109,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'r' }, showmatch = { + mode_idx = 16, blinkoff = 150, blinkon = 175, blinkwait = 175, @@ -108,12 +119,15 @@ describe('ui/cursor', function() id_lm = 46, short_name = 'sm' }, statusline_drag = { + mode_idx = 11, mouse_shape = 0, short_name = 'sd' }, statusline_hover = { + mode_idx = 10, mouse_shape = 0, short_name = 's' }, visual = { + mode_idx = 1, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -124,6 +138,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'v' }, visual_select = { + mode_idx = 8, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -134,9 +149,11 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 've' }, vsep_drag = { + mode_idx = 13, mouse_shape = 0, short_name = 'vd' }, vsep_hover = { + mode_idx = 12, mouse_shape = 0, short_name = 'vs' } } diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua new file mode 100644 index 0000000000..f0cedfeeb5 --- /dev/null +++ b/test/functional/ui/mode_spec.lua @@ -0,0 +1,227 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert +local command, eval = helpers.command, helpers.eval +local eq = helpers.eq + +describe('ui mode_change event', function() + local screen + + before_each(function() + clear() + screen = Screen.new(25, 4) + screen:attach({rgb= true}) + screen:set_default_attr_ids( { + [0] = {bold=true, foreground=255}, + [1] = {bold=true, reverse=true}, + [2] = {bold=true}, + [3] = {reverse=true}, + }) + end) + + it('works in normal mode', function() + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + + feed('d') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("operator", screen.mode) + end) + + feed('') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) + + it('works in insert mode', function() + feed('i') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]],nil,nil,function () + eq("insert", screen.mode) + end) + + feed('word') + screen:expect([[ + wor^d | + {0:~ }| + {0:~ }| + | + ]], nil, nil, function () + eq("normal", screen.mode) + end) + + command("set showmatch") + eq(eval('&matchtime'), 5) -- tenths of seconds + feed('a(stuff') + screen:expect([[ + word(stuff^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("insert", screen.mode) + end) + + feed(')') + screen:expect([[ + word^(stuff) | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("showmatch", screen.mode) + end) + + screen:sleep(400) + screen:expect([[ + word(stuff)^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("insert", screen.mode) + end) + end) + + it('works in replace mode', function() + feed('R') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {2:-- REPLACE --} | + ]], nil, nil, function () + eq("replace", screen.mode) + end) + + feed('word') + screen:expect([[ + wor^d | + {0:~ }| + {0:~ }| + | + ]], nil, nil, function () + eq("normal", screen.mode) + end) + end) + + it('works in cmdline mode', function() + feed(':') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^ | + ]],nil,nil,function () + eq("cmdline_normal", screen.mode) + end) + + feed('x') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^x | + ]],nil,nil,function () + eq("cmdline_insert", screen.mode) + end) + + feed('') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^x | + ]],nil,nil,function () + eq("cmdline_replace", screen.mode) + end) + + + feed('') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :x^ | + ]],nil,nil,function () + eq("cmdline_normal", screen.mode) + end) + + feed('') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) + + it('works in visal mode', function() + insert("text") + feed('v') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + {2:-- VISUAL --} | + ]],nil,nil,function () + eq("visual", screen.mode) + end) + + feed('') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + + command('set selection=exclusive') + feed('v') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + {2:-- VISUAL --} | + ]],nil,nil,function () + eq("visual_select", screen.mode) + end) + + feed('') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) +end) + diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index afbcd222c7..ceb82db98f 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -384,9 +384,8 @@ function Screen:_handle_mouse_off() self._mouse_enabled = false end -function Screen:_handle_mode_change(mode) - assert(mode == 'insert' or mode == 'replace' - or mode == 'normal' or mode == 'cmdline') +function Screen:_handle_mode_change(mode, idx) + assert(idx == self._cursor_style[mode].mode_idx) self.mode = mode end diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 8182190b5f..d9cb3d7b6f 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -566,119 +566,6 @@ describe('Screen', function() end) end) - describe('mode change', function() - before_each(function() - screen:try_resize(25, 5) - end) - - it('works in normal mode', function() - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) - end) - - it('works in insert mode', function() - feed('i') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- INSERT --} | - ]],nil,nil,function () - eq("insert", screen.mode) - end) - - feed('word') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in replace mode', function() - feed('R') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- REPLACE --} | - ]], nil, nil, function () - eq("replace", screen.mode) - end) - - feed('word') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in cmdline mode', function() - feed(':') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - :^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('/') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - /^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - - feed('?') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - ?^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) - end) - end) - it('nvim_ui_attach() handles very large width/height #2180', function() screen:detach() screen = Screen.new(999, 999) -- cgit From 7ea5c78687168c07bfc4582c84145e86a5252f94 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 18 Apr 2017 13:42:04 +0200 Subject: ui: use an array for mode styles --- src/nvim/api/ui.c | 10 +- src/nvim/cursor_shape.c | 14 +-- src/nvim/tui/tui.c | 25 ++--- src/nvim/ui.c | 10 +- src/nvim/ui.ch | 0 src/nvim/ui.h | 2 +- src/nvim/ui_bridge.c | 20 ++-- test/functional/ui/cursor_spec.lua | 186 +++++++++++++++++++------------------ test/functional/ui/screen.lua | 8 +- 9 files changed, 137 insertions(+), 138 deletions(-) create mode 100644 src/nvim/ui.ch diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 0053050717..3e7e2718bb 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -70,7 +70,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, ui->clear = remote_ui_clear; ui->eol_clear = remote_ui_eol_clear; ui->cursor_goto = remote_ui_cursor_goto; - ui->cursor_style_set = remote_ui_cursor_style_set; + ui->mode_info_set = remote_ui_mode_info_set; ui->update_menu = remote_ui_update_menu; ui->busy_start = remote_ui_busy_start; ui->busy_stop = remote_ui_busy_stop; @@ -295,12 +295,12 @@ static void remote_ui_scroll(UI *ui, int count) push_call(ui, "scroll", args); } -static void remote_ui_cursor_style_set(UI *ui, bool enabled, Dictionary data) +static void remote_ui_mode_info_set(UI *ui, bool guicursor_enabled, Array data) { Array args = ARRAY_DICT_INIT; - ADD(args, BOOLEAN_OBJ(enabled)); - ADD(args, copy_object(DICTIONARY_OBJ(data))); - push_call(ui, "cursor_style_set", args); + ADD(args, BOOLEAN_OBJ(guicursor_enabled)); + ADD(args, copy_object(ARRAY_OBJ(data))); + push_call(ui, "mode_info_set", args); } static void remote_ui_highlight_set(UI *ui, HlAttrs attrs) diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 57dc241c54..3099a5189b 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -34,11 +34,11 @@ cursorentry_T shape_table[SHAPE_IDX_COUNT] = { "showmatch", 0, 0, 0, 100L, 100L, 100L, 0, 0, "sm", SHAPE_CURSOR }, }; -/// Converts cursor_shapes into a Dictionary of dictionaries -/// @return dictionary of the form {"normal" : { "cursor_shape": ... }, ...} -Dictionary cursor_shape_dict(void) +/// Converts cursor_shapes into an Array of Dictionaries +/// @return Array of the form {[ "cursor_shape": ... ], ...} +Array mode_style_array(void) { - Dictionary all = ARRAY_DICT_INIT; + Array all = ARRAY_DICT_INIT; for (int i = 0; i < SHAPE_IDX_COUNT; i++) { Dictionary dic = ARRAY_DICT_INIT; @@ -62,10 +62,10 @@ Dictionary cursor_shape_dict(void) PUT(dic, "hl_id", INTEGER_OBJ(cur->id)); PUT(dic, "id_lm", INTEGER_OBJ(cur->id_lm)); } + PUT(dic, "name", STRING_OBJ(cstr_to_string(cur->full_name))); PUT(dic, "short_name", STRING_OBJ(cstr_to_string(cur->name))); - PUT(dic, "mode_idx", INTEGER_OBJ(i)); - PUT(all, cur->full_name, DICTIONARY_OBJ(dic)); + ADD(all, DICTIONARY_OBJ(dic)); } return all; @@ -241,7 +241,7 @@ char_u *parse_shape_opt(int what) shape_table[SHAPE_IDX_VE].id_lm = shape_table[SHAPE_IDX_V].id_lm; } } - ui_cursor_style_set(); + ui_mode_info_set(); return NULL; } diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 3498e8f4e7..172160fddb 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -101,7 +101,7 @@ UI *tui_start(void) ui->clear = tui_clear; ui->eol_clear = tui_eol_clear; ui->cursor_goto = tui_cursor_goto; - ui->cursor_style_set = tui_cursor_style_set; + ui->mode_info_set = tui_mode_info_set; ui->update_menu = tui_update_menu; ui->busy_start = tui_busy_start; ui->busy_stop = tui_busy_stop; @@ -451,7 +451,7 @@ CursorShape tui_cursor_decode_shape(const char *shape_str) return shape; } -static cursorentry_T decode_cursor_entry(Dictionary args, int *mode_idx) +static cursorentry_T decode_cursor_entry(Dictionary args) { cursorentry_T r; @@ -467,31 +467,26 @@ static cursorentry_T decode_cursor_entry(Dictionary args, int *mode_idx) r.blinkoff = (int)value.data.integer; } else if (strequal(key, "hl_id")) { r.id = (int)value.data.integer; - } else if (strequal(key, "mode_idx")) { - *mode_idx = (int)value.data.integer; } } return r; } -static void tui_cursor_style_set(UI *ui, bool enabled, Dictionary args) +static void tui_mode_info_set(UI *ui, bool guicursor_enabled, Array args) { - cursor_style_enabled = enabled; - if (!enabled) { + cursor_style_enabled = guicursor_enabled; + if (!guicursor_enabled) { return; // Do not send cursor style control codes. } TUIData *data = ui->data; assert(args.size); - // Keys: as defined by `shape_table`. + + // cursor style entries as defined by `shape_table`. for (size_t i = 0; i < args.size; i++) { - char *mode_name = args.items[i].key.data; - int mode_idx; - cursorentry_T r = decode_cursor_entry(args.items[i].value.data.dictionary, - &mode_idx); - assert(mode_idx >= 0); - r.full_name = mode_name; - data->cursor_shapes[mode_idx] = r; + assert(args.items[i].type == kObjectTypeDictionary); + cursorentry_T r = decode_cursor_entry(args.items[i].data.dictionary); + data->cursor_shapes[i] = r; } tui_set_mode(ui, data->showing_mode); diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 8c5e579301..5fb57dd257 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -175,7 +175,7 @@ void ui_refresh(void) row = col = 0; screen_resize(width, height); pum_set_external(pum_external); - ui_cursor_style_set(); + ui_mode_info_set(); old_mode_idx = -1; ui_cursor_shape(); } @@ -375,12 +375,12 @@ void ui_cursor_goto(int new_row, int new_col) pending_cursor_update = true; } -void ui_cursor_style_set(void) +void ui_mode_info_set(void) { - Dictionary style = cursor_shape_dict(); + Array style = mode_style_array(); bool enabled = (*p_guicursor != NUL); - UI_CALL(cursor_style_set, enabled, style); - api_free_dictionary(style); + UI_CALL(mode_info_set, enabled, style); + api_free_array(style); } void ui_update_menu(void) diff --git a/src/nvim/ui.ch b/src/nvim/ui.ch new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/nvim/ui.h b/src/nvim/ui.h index d63ceb106c..f5cbf748ee 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -22,7 +22,7 @@ struct ui_t { void (*clear)(UI *ui); void (*eol_clear)(UI *ui); void (*cursor_goto)(UI *ui, int row, int col); - void (*cursor_style_set)(UI *ui, bool enabled, Dictionary cursor_styles); + void (*mode_info_set)(UI *ui, bool enabled, Array cursor_styles); void (*update_menu)(UI *ui); void (*busy_start)(UI *ui); void (*busy_stop)(UI *ui); diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index 59942fb2cb..e899cbf397 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -60,7 +60,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) rv->bridge.clear = ui_bridge_clear; rv->bridge.eol_clear = ui_bridge_eol_clear; rv->bridge.cursor_goto = ui_bridge_cursor_goto; - rv->bridge.cursor_style_set = ui_bridge_cursor_style_set; + rv->bridge.mode_info_set = ui_bridge_mode_info_set; rv->bridge.update_menu = ui_bridge_update_menu; rv->bridge.busy_start = ui_bridge_busy_start; rv->bridge.busy_stop = ui_bridge_busy_stop; @@ -180,23 +180,23 @@ static void ui_bridge_cursor_goto_event(void **argv) ui->cursor_goto(ui, PTR2INT(argv[1]), PTR2INT(argv[2])); } -static void ui_bridge_cursor_style_set(UI *b, bool enabled, Dictionary styles) +static void ui_bridge_mode_info_set(UI *b, bool enabled, Array modes) { bool *enabledp = xmalloc(sizeof(*enabledp)); - Object *stylesp = xmalloc(sizeof(*stylesp)); + Object *modesp = xmalloc(sizeof(*modesp)); *enabledp = enabled; - *stylesp = copy_object(DICTIONARY_OBJ(styles)); - UI_CALL(b, cursor_style_set, 3, b, enabledp, stylesp); + *modesp = copy_object(ARRAY_OBJ(modes)); + UI_CALL(b, mode_info_set, 3, b, enabledp, modesp); } -static void ui_bridge_cursor_style_set_event(void **argv) +static void ui_bridge_mode_info_set_event(void **argv) { UI *ui = UI(argv[0]); bool *enabled = argv[1]; - Object *styles = argv[2]; - ui->cursor_style_set(ui, *enabled, styles->data.dictionary); + Object *modes = argv[2]; + ui->mode_info_set(ui, *enabled, modes->data.array); xfree(enabled); - api_free_object(*styles); - xfree(styles); + api_free_object(*modes); + xfree(modes); } static void ui_bridge_update_menu(UI *b) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index e4c1b17ef3..abe0e0b1fd 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -18,155 +18,155 @@ describe('ui/cursor', function() end) it("'guicursor' is published as a UI event", function() - local expected_cursor_style = { - cmdline_hover = { - mode_idx = 9, - mouse_shape = 0, - short_name = 'e' }, - cmdline_insert = { - mode_idx = 5, + local expected_mode_info = { + [1] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 25, - cursor_shape = 'vertical', + cell_percentage = 0, + cursor_shape = 'block', + name = 'normal', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'ci' }, - cmdline_normal = { - mode_idx = 4, + short_name = 'n' }, + [2] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', + name = 'visual', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'c' }, - cmdline_replace = { - mode_idx = 6, + short_name = 'v' }, + [3] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 20, - cursor_shape = 'horizontal', + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'insert', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'cr' }, - insert = { - mode_idx = 2, + short_name = 'i' }, + [4] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 25, - cursor_shape = 'vertical', + cell_percentage = 20, + cursor_shape = 'horizontal', + name = 'replace', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'i' }, - more = { - mode_idx = 14, - mouse_shape = 0, - short_name = 'm' }, - more_lastline = { - mode_idx = 15, - mouse_shape = 0, - short_name = 'ml' }, - normal = { - mode_idx = 0, + short_name = 'r' }, + [5] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', + name = 'cmdline_normal', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'n' }, - operator = { - mode_idx = 7, + short_name = 'c' }, + [6] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 50, - cursor_shape = 'horizontal', + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'cmdline_insert', hl_id = 46, - id_lm = 46, + id_lm = 47, mouse_shape = 0, - short_name = 'o' }, - replace = { - mode_idx = 3, + short_name = 'ci' }, + [7] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 20, cursor_shape = 'horizontal', + name = 'cmdline_replace', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'r' }, - showmatch = { - mode_idx = 16, - blinkoff = 150, - blinkon = 175, - blinkwait = 175, - cell_percentage = 0, - cursor_shape = 'block', - hl_id = 46, - id_lm = 46, - short_name = 'sm' }, - statusline_drag = { - mode_idx = 11, - mouse_shape = 0, - short_name = 'sd' }, - statusline_hover = { - mode_idx = 10, - mouse_shape = 0, - short_name = 's' }, - visual = { - mode_idx = 1, + short_name = 'cr' }, + [8] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 0, - cursor_shape = 'block', + cell_percentage = 50, + cursor_shape = 'horizontal', + name = 'operator', hl_id = 46, - id_lm = 47, + id_lm = 46, mouse_shape = 0, - short_name = 'v' }, - visual_select = { - mode_idx = 8, + short_name = 'o' }, + [9] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 35, cursor_shape = 'vertical', + name = 'visual_select', hl_id = 46, id_lm = 46, mouse_shape = 0, short_name = 've' }, - vsep_drag = { - mode_idx = 13, + [10] = { + name = 'cmdline_hover', + mouse_shape = 0, + short_name = 'e' }, + [11] = { + name = 'statusline_hover', + mouse_shape = 0, + short_name = 's' }, + [12] = { + name = 'statusline_drag', + mouse_shape = 0, + short_name = 'sd' }, + [13] = { + name = 'vsep_hover', + mouse_shape = 0, + short_name = 'vs' }, + [14] = { + name = 'vsep_drag', mouse_shape = 0, short_name = 'vd' }, - vsep_hover = { - mode_idx = 12, + [15] = { + name = 'more', mouse_shape = 0, - short_name = 'vs' } - } + short_name = 'm' }, + [16] = { + name = 'more_lastline', + mouse_shape = 0, + short_name = 'ml' }, + [17] = { + blinkoff = 150, + blinkon = 175, + blinkwait = 175, + cell_percentage = 0, + cursor_shape = 'block', + name = 'showmatch', + hl_id = 46, + id_lm = 46, + short_name = 'sm' }, + } screen:expect(function() -- Default 'guicursor' published on startup. - eq(expected_cursor_style, screen._cursor_style) + eq(expected_mode_info, screen._mode_info) eq(true, screen._cursor_style_enabled) eq('normal', screen.mode) end) -- Event is published ONLY if the cursor style changed. - screen._cursor_style = nil + screen._mode_info = nil command("echo 'test'") screen:expect([[ ^ | @@ -175,20 +175,24 @@ describe('ui/cursor', function() ~ | test | ]], nil, nil, function() - eq(nil, screen._cursor_style) + eq(nil, screen._mode_info) end) -- Change the cursor style. meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') screen:expect(function() - eq('vertical', screen._cursor_style.normal.cursor_shape) - eq('horizontal', screen._cursor_style.visual_select.cursor_shape) - eq('vertical', screen._cursor_style.operator.cursor_shape) - eq('block', screen._cursor_style.insert.cursor_shape) - eq('vertical', screen._cursor_style.showmatch.cursor_shape) - eq(171, screen._cursor_style.normal.blinkwait) - eq(172, screen._cursor_style.normal.blinkoff) - eq(173, screen._cursor_style.normal.blinkon) + local named = {} + for _, m in ipairs(screen._mode_info) do + named[m.name] = m + end + eq('vertical', named.normal.cursor_shape) + eq('horizontal', named.visual_select.cursor_shape) + eq('vertical', named.operator.cursor_shape) + eq('block', named.insert.cursor_shape) + eq('vertical', named.showmatch.cursor_shape) + eq(171, named.normal.blinkwait) + eq(172, named.normal.blinkoff) + eq(173, named.normal.blinkon) end) end) @@ -197,11 +201,11 @@ describe('ui/cursor', function() screen:expect(function() -- Empty 'guicursor' sets enabled=false. eq(false, screen._cursor_style_enabled) - for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', - 'showmatch', 'normal', 'replace', 'visual', - 'visual_select', }) do - eq('block', screen._cursor_style[m].cursor_shape) - eq(0, screen._cursor_style[m].blinkon) + for _, m in ipairs(screen._mode_info) do + if m['cursor_shape'] ~= nil then + eq('block', m.cursor_shape) + eq(0, m.blinkon) + end end end) end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index ceb82db98f..bcf2a2e3d6 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -348,9 +348,9 @@ function Screen:_handle_resize(width, height) } end -function Screen:_handle_cursor_style_set(enabled, style) - self._cursor_style_enabled = enabled - self._cursor_style = style +function Screen:_handle_mode_info_set(cursor_style_enabled, mode_info) + self._cursor_style_enabled = cursor_style_enabled + self._mode_info = mode_info end function Screen:_handle_clear() @@ -385,7 +385,7 @@ function Screen:_handle_mouse_off() end function Screen:_handle_mode_change(mode, idx) - assert(idx == self._cursor_style[mode].mode_idx) + assert(mode == self._mode_info[idx+1].name) self.mode = mode end -- cgit From 9cc97896813fa4f40a4e37b6f72284cdb10c4195 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 17 Apr 2017 16:29:15 +0200 Subject: ui: document new mode index and add note about forward-compatibility --- runtime/doc/msgpack_rpc.txt | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt index 3f3c41f566..d05e88d483 100644 --- a/runtime/doc/msgpack_rpc.txt +++ b/runtime/doc/msgpack_rpc.txt @@ -270,10 +270,14 @@ a dictionary with these (optional) keys: Defaults to false. Nvim will then send msgpack-rpc notifications, with the method name "redraw" -and a single argument, an array of screen updates (described below). -These should be processed in order. Preferably the user should only be able to -see the screen state after all updates are processed (not any intermediate -state after processing only a part of the array). +and a single argument, an array of screen updates (described below). These +should be processed in order. Preferably the user should only be able to see +the screen state after all updates in the same "redraw" event are processed +(not any intermediate state after processing only a part of the array). + +Future versions of Nvim may add new update kinds and may append new parameters +to existing update kinds. Clients must be prepared to ignore such extensions +to be forward-compatible. |api-contract| Screen updates are arrays. The first element a string describing the kind of update. @@ -387,10 +391,31 @@ of update. ["update_menu"] The menu mappings changed. -["mode_change", mode] - The mode changed. Currently sent when "insert", "replace", "cmdline" and - "normal" modes are entered. A client could for instance change the cursor - shape. +["mode_info_set", cursor_style_enabled, mode_info] +`mode_info` is an array containing information about various modes, as later +will be indicated with the `mode_change` update. Currently this primarily +concerns cursor styles to be set in the different modes. The keys are + + `cursor_shape`: One of "block", "horizontal" or "vertical" + `cell_percentage`:Percentage of the cell taken by the cursor. + `blinkwait`, `blinkon`, `blinkoff`: see |cursor-blinking|. + `hl_id`: Highlight group for the cursor. + `hl_lm`: Highlight group for the cursor when langmap is active. + `short_name`: Short name for the mode, as used in 'guicursor' + option. + `name`: Full name for the mode. + `mouse_shape`: (To be implemented.) + +Not all keys need to be present for all modes. `cursor_style_enabled` is a +boolean indicating if the ui should change the cursor style. + +["mode_change", mode, mode_idx] +The mode changed. The first parameter `mode` is a string representing the +current mode. `mode_idx` is an index into the array received in the +`mode_info_set` event. UIs should change the cursor style according to the +properties specified in the corresponding item. The set of modes reported will +change in new versions of Nvim, for instance more submodes and temporary +states might be represented as separate modes. ["popupmenu_show", items, selected, row, col] When `popupmenu_external` is set to true, nvim will not draw the -- cgit From 48f0542ad6f923443ab4bba858aae2d9558f8d76 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 21 Apr 2017 10:59:06 +0200 Subject: tests: detect invalid helpers.sleep --- test/functional/ex_cmds/ctrl_c_spec.lua | 2 +- test/functional/helpers.lua | 11 ++++++++++- test/functional/terminal/ex_terminal_spec.lua | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua index 993bfa0dba..091a008814 100644 --- a/test/functional/ex_cmds/ctrl_c_spec.lua +++ b/test/functional/ex_cmds/ctrl_c_spec.lua @@ -41,7 +41,7 @@ describe("CTRL-C (mapped)", function() local function test_ctrl_c(ms) feed(":global/^/p") - helpers.sleep(ms) + screen:sleep(ms) feed("") screen:expect([[Interrupt]], nil, nil, nil, true) end diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 5882758b5a..84e81c5af4 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -392,7 +392,16 @@ end -- sleeps the test runner (_not_ the nvim instance) local function sleep(ms) - run(nil, nil, nil, ms) + local function notification_cb(method, args) + local _ = args + if method == "redraw" then + error("helpers.sleep() called while screen is attached. ".. + "Use screen:sleep(...) instead") + end + return true + end + + run(nil, notification_cb, nil, ms) end local function curbuf_contents() diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 1ed63adcfb..be0fd9f8ff 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -26,7 +26,7 @@ describe(':terminal', function() feed_command([[terminal while true; do echo X; done]]) helpers.feed([[]]) wait() - screen.sleep(10) -- Let some terminal activity happen. + screen:sleep(10) -- Let some terminal activity happen. feed_command("messages") screen:expect([[ msg1 | -- cgit