diff options
-rw-r--r-- | src/nvim/edit.c | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 5 | ||||
-rw-r--r-- | src/nvim/getchar.c | 5 | ||||
-rw-r--r-- | src/nvim/main.c | 1 | ||||
-rw-r--r-- | src/nvim/message.c | 1 | ||||
-rw-r--r-- | src/nvim/misc1.c | 2 | ||||
-rw-r--r-- | src/nvim/misc2.c | 1 | ||||
-rw-r--r-- | src/nvim/msgpack_rpc/remote_ui.c | 12 | ||||
-rw-r--r-- | src/nvim/normal.c | 3 | ||||
-rw-r--r-- | src/nvim/option.c | 1 | ||||
-rw-r--r-- | src/nvim/os/event.h | 12 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 5 | ||||
-rw-r--r-- | src/nvim/os_unix.c | 10 | ||||
-rw-r--r-- | src/nvim/screen.c | 6 | ||||
-rw-r--r-- | src/nvim/search.c | 1 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 20 | ||||
-rw-r--r-- | src/nvim/ui.c | 22 | ||||
-rw-r--r-- | src/nvim/ui.h | 4 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 13 |
21 files changed, 57 insertions, 76 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 14b3968f2d..516278f34d 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1400,7 +1400,6 @@ void display_dollar(colnr_T col) if (!redrawing()) return; - ui_cursor_off(); save_col = curwin->w_cursor.col; curwin->w_cursor.col = col; if (has_mbyte) { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 739243cbee..c4b6b701d9 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1063,9 +1063,7 @@ do_filter ( /* Create the shell command in allocated memory. */ cmd_buf = make_filter_cmd(cmd, itmp, otmp); - ui_cursor_goto((int)Rows - 1, 0); - ui_cursor_on(); /* * When not redirecting the output the command can write anything to the @@ -1248,7 +1246,6 @@ do_shell ( // This ui_cursor_goto is required for when the '\n' resulted in a "delete line // 1" command to the terminal. ui_cursor_goto(msg_row, msg_col); - ui_cursor_on(); (void)call_shell(cmd, flags, NULL); did_check_timestamps = FALSE; need_check_timestamps = TRUE; @@ -1963,7 +1960,6 @@ void print_line(linenr_T lnum, int use_number, int list) print_line_no_prefix(lnum, use_number, list); if (save_silent) { msg_putchar('\n'); - ui_cursor_on(); /* msg_start() switches it off */ ui_flush(); silent_mode = save_silent; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 8167824a41..63d94dabc0 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -6381,9 +6381,7 @@ static void ex_sleep(exarg_T *eap) void do_sleep(long msec) { long done; - - ui_cursor_on(); - ui_flush(); + ui_flush(); // flush before waiting for (done = 0; !got_int && done < msec; done += 1000L) { os_delay(msec - done > 1000L ? 1000L : msec - done, true); os_breakcheck(); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a7bb4afa70..c9e990b713 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1364,7 +1364,6 @@ cmdline_changed: if (ccline.cmdlen == 0) i = 0; else { - ui_cursor_off(); /* so the user knows we're busy */ ui_flush(); ++emsg_off; /* So it doesn't beep if bad expr */ /* Set the time limit to half a second. */ @@ -1701,10 +1700,6 @@ getexmodeline ( char_u *p; int prev_char; - /* Switch cursor on now. This avoids that it happens after the "\n", which - * confuses the system function that computes tabstops. */ - ui_cursor_on(); - /* always start in column 0; write a newline if necessary */ compute_cmdrow(); if ((msg_col || msg_didout) && promptc != '?') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b3e274d952..41b3d9dda8 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2379,11 +2379,6 @@ inchar ( int retesc = FALSE; /* return ESC with gotint */ int script_char; - if (wait_time == -1L || wait_time > 100L) { /* flush output before waiting */ - ui_cursor_on(); - ui_flush(); - } - /* * Don't reset these when at the hit-return prompt, otherwise an endless * recursive loop may result (write error in swapfile, hit-return, timeout diff --git a/src/nvim/main.c b/src/nvim/main.c index a4f430e811..76fee17726 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -641,7 +641,6 @@ main_loop ( curwin->w_valid &= ~VALID_CROW; } setcursor(); - ui_cursor_on(); do_redraw = FALSE; diff --git a/src/nvim/message.c b/src/nvim/message.c index 3a68de8881..91c7d05ff4 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -998,7 +998,6 @@ void msg_start(void) msg_starthere(); if (msg_silent == 0) { msg_didout = FALSE; /* no output on current line yet */ - ui_cursor_off(); } /* when redirecting, may need to start a new line. */ diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 3ed6b416d6..9c08a7c1f7 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2364,8 +2364,6 @@ int get_keystroke(void) mapped_ctrl_c = FALSE; /* mappings are not used here */ for (;; ) { - ui_cursor_on(); - ui_flush(); /* Leave some room for check_termcode() to insert a key code into (max * 5 chars plus NUL). And fix_input_buffer() can triple the number of diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index be5150fdc0..06196b32af 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -297,7 +297,6 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) smsg((char_u *)_("Calling shell to execute: \"%s\""), cmd == NULL ? p_sh : cmd); ui_putc('\n'); - ui_cursor_on(); verbose_leave(); } diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index 45b3dee0fd..b554d76bed 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -82,8 +82,8 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, ui->clear = remote_ui_clear; ui->eol_clear = remote_ui_eol_clear; ui->cursor_goto = remote_ui_cursor_goto; - ui->cursor_on = remote_ui_cursor_on; - ui->cursor_off = remote_ui_cursor_off; + ui->busy_start = remote_ui_busy_start; + ui->busy_stop = remote_ui_busy_stop; ui->mouse_on = remote_ui_mouse_on; ui->mouse_off = remote_ui_mouse_off; ui->insert_mode = remote_ui_insert_mode; @@ -190,16 +190,16 @@ static void remote_ui_cursor_goto(UI *ui, int row, int col) push_call(ui, "cursor_goto", args); } -static void remote_ui_cursor_on(UI *ui) +static void remote_ui_busy_start(UI *ui) { Array args = ARRAY_DICT_INIT; - push_call(ui, "cursor_on", args); + push_call(ui, "busy_start", args); } -static void remote_ui_cursor_off(UI *ui) +static void remote_ui_busy_stop(UI *ui) { Array args = ARRAY_DICT_INIT; - push_call(ui, "cursor_off", args); + push_call(ui, "busy_stop", args); } static void remote_ui_mouse_on(UI *ui) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 4c62b0c28d..a708aca136 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -983,7 +983,6 @@ getcount: free(kmsg); } setcursor(); - ui_cursor_on(); ui_flush(); if (msg_scroll || emsg_on_display) os_delay(1000L, true); /* wait at least one second */ @@ -2998,8 +2997,6 @@ static void display_showcmd(void) { int len; - ui_cursor_off(); - len = (int)STRLEN(showcmd_buf); if (len == 0) showcmd_is_clear = true; diff --git a/src/nvim/option.c b/src/nvim/option.c index a9e271517d..2998f89edb 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3042,7 +3042,6 @@ theend: silent_mode = FALSE; info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ msg_putchar('\n'); - ui_cursor_on(); /* msg_start() switches it off */ ui_flush(); silent_mode = TRUE; info_message = FALSE; /* use mch_msg(), not mch_errmsg() */ diff --git a/src/nvim/os/event.h b/src/nvim/os/event.h index f8139e978d..986db51431 100644 --- a/src/nvim/os/event.h +++ b/src/nvim/os/event.h @@ -8,9 +8,15 @@ #include "nvim/os/job_defs.h" #include "nvim/os/time.h" -// Poll for events until a condition is true or a timeout has passed +void ui_busy_start(void); +void ui_busy_stop(void); + +// Poll for events until a condition or timeout #define event_poll_until(timeout, condition) \ do { \ + if (timeout < 0 || timeout > 100) { \ + ui_busy_stop(); \ + } \ int remaining = timeout; \ uint64_t before = (remaining > 0) ? os_hrtime() : 0; \ while (!(condition)) { \ @@ -26,9 +32,13 @@ } \ } \ } \ + if (timeout < 0 || timeout > 100) { \ + ui_busy_start(); \ + } \ } while (0) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/event.h.generated.h" #endif + #endif // NVIM_OS_EVENT_H diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 8cf7e7161d..290d6a9ec9 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -99,7 +99,6 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) char *output = NULL, **output_ptr = NULL; int current_state = State; bool forward_output = true; - ui_flush(); // While the child is running, ignore terminating signals signal_reject_deadly(); @@ -239,7 +238,11 @@ static int shell(const char *cmd, job_close_in(job); } + // invoke busy_start here so event_poll_until wont change the busy state for + // the UI + ui_busy_start(); status = job_wait(job, -1); + ui_busy_stop(); // prepare the out parameters if requested if (output) { diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 5d8b4ad26a..8e4569033a 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -232,15 +232,7 @@ void mch_exit(int r) { exiting = TRUE; - { - ui_builtin_stop(); - - // Cursor may have been switched off without calling starttermcap() - // when doing "vim -u vimrc" and vimrc contains ":q". */ - if (full_screen) { - ui_cursor_on(); - } - } + ui_builtin_stop(); ui_flush(); ml_close_all(TRUE); /* remove all memfiles */ diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 757bdb34b1..04a092c4f7 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -416,7 +416,6 @@ void update_screen(int type) search_hl.rm.regprog = NULL; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->w_redr_type != 0) { - ui_cursor_off(); if (!did_one) { did_one = TRUE; start_search_hl(); @@ -426,7 +425,6 @@ void update_screen(int type) /* redraw status line after the window to minimize cursor movement */ if (wp->w_redr_status) { - ui_cursor_off(); win_redr_status(wp); } } @@ -521,7 +519,6 @@ void update_single_line(win_T *wp, linenr_T lnum) */ static void update_prepare(void) { - ui_cursor_off(); updating_screen = TRUE; start_search_hl(); } @@ -6566,7 +6563,6 @@ int showmode(void) /* Position on the last line in the window, column 0 */ msg_pos_mode(); - ui_cursor_off(); attr = hl_attr(HLF_CM); /* Highlight mode */ if (do_mode) { MSG_PUTS_ATTR("--", attr); @@ -7015,7 +7011,6 @@ static void win_redr_ruler(win_T *wp, int always) || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count || wp->w_topfill != wp->w_ru_topfill || empty_line != wp->w_ru_empty) { - ui_cursor_off(); int width; int row; @@ -7238,7 +7233,6 @@ void screen_resize(int width, int height) setcursor(); } } - ui_cursor_on(); /* redrawing may have switched it off */ } ui_flush(); --busy; diff --git a/src/nvim/search.c b/src/nvim/search.c index 6e2824bc8e..26ff9a5bad 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2044,7 +2044,6 @@ showmatch ( p_siso = 0; /* don't use 'sidescrolloff' here */ showruler(FALSE); setcursor(); - ui_cursor_on(); /* make sure that the cursor is shown */ ui_flush(); /* Restore dollar_vcol(), because setcursor() may call curs_rows() * which resets it if the matching position is in a previous line diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index b95a22d48b..610419d12c 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -45,6 +45,7 @@ typedef struct { int out_fd; int old_height; bool can_use_terminal_scroll; + bool busy; HlAttrs attrs, print_attrs; Cell **screen; struct { @@ -80,6 +81,7 @@ typedef struct { void tui_start(void) { TUIData *data = xcalloc(1, sizeof(TUIData)); + data->busy = true; UI *ui = xcalloc(1, sizeof(UI)); ui->data = data; data->attrs = data->print_attrs = EMPTY_ATTRS; @@ -134,8 +136,8 @@ void tui_start(void) ui->clear = tui_clear; ui->eol_clear = tui_eol_clear; ui->cursor_goto = tui_cursor_goto; - ui->cursor_on = tui_cursor_on; - ui->cursor_off = tui_cursor_off; + ui->busy_start = tui_busy_start; + ui->busy_stop = tui_busy_stop; ui->mouse_on = tui_mouse_on; ui->mouse_off = tui_mouse_off; ui->insert_mode = tui_insert_mode; @@ -342,14 +344,14 @@ static void tui_cursor_goto(UI *ui, int row, int col) unibi_goto(ui, row, col); } -static void tui_cursor_on(UI *ui) +static void tui_busy_start(UI *ui) { - unibi_out(ui, unibi_cursor_normal); + ((TUIData *)ui->data)->busy = true; } -static void tui_cursor_off(UI *ui) +static void tui_busy_stop(UI *ui) { - unibi_out(ui, unibi_cursor_invisible); + ((TUIData *)ui->data)->busy = false; } static void tui_mouse_on(UI *ui) @@ -527,7 +529,13 @@ static void tui_flush(UI *ui) } unibi_goto(ui, data->row, data->col); + + if (!data->busy) { + unibi_out(ui, unibi_cursor_normal); + } + flush_buf(ui); + unibi_out(ui, unibi_cursor_invisible); } static void tui_suspend(UI *ui) diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 62cc662b5b..0283e7bd62 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -44,7 +44,8 @@ static struct { int top, bot, left, right; } sr; static int current_attr_code = 0; -static bool cursor_enabled = true, pending_cursor_update = false; +static bool pending_cursor_update = false; +static int busy = 1; static int height, width; // This set of macros allow us to use UI_CALL to invoke any function on @@ -150,24 +151,23 @@ void ui_resize(int new_width, int new_height) UI_CALL(resize, width, height); } -void ui_cursor_on(void) +void ui_busy_start(void) { - if (!cursor_enabled) { - UI_CALL(cursor_on); - cursor_enabled = true; + if (!(busy++)) { + UI_CALL(busy_start); } + ui_flush(); } -void ui_cursor_off(void) +void ui_busy_stop(void) { - if (full_screen) { - if (cursor_enabled) { - UI_CALL(cursor_off); - } - cursor_enabled = false; + if (!(--busy)) { + UI_CALL(busy_stop); } + ui_flush(); } + void ui_mouse_on(void) { UI_CALL(mouse_on); diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 4bc3983578..71ed9b3097 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -20,8 +20,8 @@ struct ui_t { void (*clear)(UI *ui); void (*eol_clear)(UI *ui); void (*cursor_goto)(UI *ui, int row, int col); - void (*cursor_on)(UI *ui); - void (*cursor_off)(UI *ui); + void (*busy_start)(UI *ui); + void (*busy_stop)(UI *ui); void (*mouse_on)(UI *ui); void (*mouse_off)(UI *ui); void (*insert_mode)(UI *ui); diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 585037466e..7ba90abde2 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -164,8 +164,9 @@ function Screen.new(width, height) _mouse_enabled = true, _attrs = {}, _cursor = { - enabled = true, row = 1, col = 1 - } + row = 1, col = 1 + }, + _busy = true }, Screen) self:_handle_resize(width, height) return self @@ -282,12 +283,12 @@ function Screen:_handle_cursor_goto(row, col) self._cursor.col = col + 1 end -function Screen:_handle_cursor_on() - self._cursor.enabled = true +function Screen:_handle_busy_start() + self._busy = true end -function Screen:_handle_cursor_off() - self._cursor.enabled = false +function Screen:_handle_busy_stop() + self._busy = false end function Screen:_handle_mouse_on() |