diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-11-27 16:08:44 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-11-27 16:08:44 -0300 |
commit | dca8853f0031ab7ac960037d3b848107355d7056 (patch) | |
tree | 90cecee10a75f8035fd0df02629d999853318450 /src | |
parent | f6c89ec70409badb7ca477de47dd1f8dbf3de376 (diff) | |
parent | bf6bb27e79f53646309ba075655465919bc2e60c (diff) | |
download | rneovim-dca8853f0031ab7ac960037d3b848107355d7056.tar.gz rneovim-dca8853f0031ab7ac960037d3b848107355d7056.tar.bz2 rneovim-dca8853f0031ab7ac960037d3b848107355d7056.zip |
Merge PR #1565 'Cleanup ui module'
Diffstat (limited to 'src')
39 files changed, 601 insertions, 697 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 6b5b97fe67..ec10a826c7 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -69,10 +69,11 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/time.h" +#include "nvim/os/input.h" #define HAVE_BUFLIST_MATCH @@ -716,7 +717,7 @@ do_bufdel ( } else /* addr_count == 1 */ bnr = end_bnr; - for (; !got_int; ui_breakcheck()) { + for (; !got_int; os_breakcheck()) { /* * delete the current buffer last, otherwise when the * current buffer is deleted, the next buffer becomes @@ -1422,7 +1423,7 @@ buflist_new ( EMSG(_("W14: Warning: List of file names overflow")); if (emsg_silent == 0) { out_flush(); - ui_delay(3000L, true); /* make sure it is noticed */ + os_delay(3000L, true); /* make sure it is noticed */ } top_file_num = 1; } @@ -2162,7 +2163,7 @@ void buflist_list(exarg_T *eap) : (int64_t)buflist_findlnum(buf)); msg_outtrans(IObuff); out_flush(); /* output one line at a time */ - ui_breakcheck(); + os_breakcheck(); } } @@ -3801,7 +3802,7 @@ do_arg_all ( ++autocmd_no_leave; use_firstwin = FALSE; } - ui_breakcheck(); + os_breakcheck(); /* When ":tab" was used open a new tab for a new window repeatedly. */ if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) @@ -3965,7 +3966,7 @@ void ex_buffer_all(exarg_T *eap) #endif } - ui_breakcheck(); + os_breakcheck(); if (got_int) { (void)vgetc(); /* only break the file loading, not the rest */ break; diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index ffba7d4276..440d07aab0 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -23,7 +23,7 @@ #include "nvim/normal.h" #include "nvim/screen.h" #include "nvim/strings.h" -#include "nvim/ui.h" +#include "nvim/os/input.h" typedef int result_T; @@ -1659,13 +1659,13 @@ void listdigraphs(void) printdigraph(&tmp); } dp++; - ui_breakcheck(); + os_breakcheck(); } dp = (digr_T *)user_digraphs.ga_data; for (int i = 0; i < user_digraphs.ga_len && !got_int; ++i) { printdigraph(dp); - ui_breakcheck(); + os_breakcheck(); dp++; } // clear screen, because some digraphs may be wrong, in which case we messed diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b9ecbc71fe..2cc91a2591 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -56,9 +56,12 @@ #include "nvim/tag.h" #include "nvim/term.h" #include "nvim/ui.h" +#include "nvim/mouse.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/event.h" +#include "nvim/os/input.h" +#include "nvim/os/time.h" /* * definitions used for CTRL-X submode @@ -1761,7 +1764,7 @@ static int has_compl_option(int dict_opt) vim_beep(); setcursor(); out_flush(); - ui_delay(2000L, false); + os_delay(2000L, false); } return FALSE; } @@ -2005,7 +2008,7 @@ ins_compl_add ( compl_T *match; int dir = (cdir == 0 ? compl_direction : cdir); - ui_breakcheck(); + os_breakcheck(); if (got_int) return FAIL; if (len < 0) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4a77bcd3c5..34990a62e0 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -76,7 +76,7 @@ #include "nvim/tag.h" #include "nvim/tempfile.h" #include "nvim/term.h" -#include "nvim/ui.h" +#include "nvim/mouse.h" #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" @@ -90,6 +90,7 @@ #include "nvim/api/vim.h" #include "nvim/os/dl.h" #include "nvim/os/event.h" +#include "nvim/os/input.h" #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ @@ -10273,12 +10274,6 @@ static void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog) rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; -#ifdef NO_CONSOLE_INPUT - /* While starting up, there is no place to enter text. */ - if (no_console_input()) - return; -#endif - cmd_silent = FALSE; /* Want to see the prompt. */ if (prompt != NULL) { /* Only the part of the message after the last NL is considered as @@ -10373,11 +10368,6 @@ static void f_inputlist(typval_T *argvars, typval_T *rettv) int selected; int mouse_used; -#ifdef NO_CONSOLE_INPUT - /* While starting up, there is no place to enter text. */ - if (no_console_input()) - return; -#endif if (argvars[0].v_type != VAR_LIST || argvars[0].vval.v_list == NULL) { EMSG2(_(e_listarg), "inputlist()"); return; @@ -17281,7 +17271,7 @@ void ex_function(exarg_T *eap) msg_putchar(' '); msg_prt_line(FUNCLINE(fp, j), FALSE); out_flush(); /* show a line at a time */ - ui_breakcheck(); + os_breakcheck(); } if (!got_int) { msg_putchar('\n'); @@ -19306,7 +19296,7 @@ void ex_oldfiles(exarg_T *eap) msg_outtrans(get_tv_string(&li->li_tv)); msg_putchar('\n'); out_flush(); /* output one line at a time */ - ui_breakcheck(); + os_breakcheck(); } /* Assume "got_int" was set to truncate the listing. */ got_int = FALSE; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f33a96cc50..556e0c01e3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -62,11 +62,11 @@ #include "nvim/tag.h" #include "nvim/tempfile.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/shell.h" +#include "nvim/os/input.h" /* * Struct to hold the sign properties. @@ -1110,7 +1110,7 @@ do_filter ( /* When interrupting the shell command, it may still have produced some * useful output. Reset got_int here, so that readfile() won't cancel * reading. */ - ui_breakcheck(); + os_breakcheck(); got_int = FALSE; if (do_out) { @@ -4560,7 +4560,7 @@ void global_exe(char_u *cmd) do_cmdline((char_u *)"p", NULL, NULL, DOCMD_NOWAIT); else do_cmdline(cmd, NULL, NULL, DOCMD_NOWAIT); - ui_breakcheck(); + os_breakcheck(); } global_busy = 0; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 3e9b889253..3967c916bb 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -67,6 +67,8 @@ #include "nvim/version.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" +#include "nvim/os/time.h" #include "nvim/ex_cmds_defs.h" static int quitmore = 0; @@ -4337,7 +4339,7 @@ static void uc_list(char_u *name, size_t name_len) if (p_verbose > 0) last_set_msg(cmd->uc_scriptID); out_flush(); - ui_breakcheck(); + os_breakcheck(); if (got_int) break; } @@ -5459,7 +5461,7 @@ static void ex_print(exarg_T *eap) if (curbuf->b_ml.ml_flags & ML_EMPTY) EMSG(_(e_emptybuf)); else { - for (; !got_int; ui_breakcheck()) { + for (; !got_int; os_breakcheck()) { print_line(eap->line1, (eap->cmdidx == CMD_number || eap->cmdidx == CMD_pound || (eap->flags & EXFLAG_NR)), @@ -5586,7 +5588,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum buf_set_name(fnum_list[i], files[i]); alist_add(al, files[i], use_curbuf ? 2 : 1); - ui_breakcheck(); + os_breakcheck(); } free(files); } @@ -5842,7 +5844,7 @@ static void ex_tabs(exarg_T *eap) vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++); msg_outtrans_attr(IObuff, hl_attr(HLF_T)); out_flush(); /* output one line at a time */ - ui_breakcheck(); + os_breakcheck(); FOR_ALL_WINDOWS_IN_TAB(wp, tp) { if (got_int) { @@ -5861,7 +5863,7 @@ static void ex_tabs(exarg_T *eap) IObuff, IOSIZE, TRUE); msg_outtrans(IObuff); out_flush(); /* output one line at a time */ - ui_breakcheck(); + os_breakcheck(); } } } @@ -6408,8 +6410,8 @@ void do_sleep(long msec) cursor_on(); out_flush(); for (done = 0; !got_int && done < msec; done += 1000L) { - ui_delay(msec - done > 1000L ? 1000L : msec - done, true); - ui_breakcheck(); + 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 2be3757821..a19423532d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1946,7 +1946,7 @@ redraw: msg_col = 0; if (msg_row < Rows - 1) ++msg_row; - emsg_on_display = FALSE; /* don't want ui_delay() */ + emsg_on_display = FALSE; /* don't want os_delay() */ if (got_int) ga_clear(&line_ga); diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 955b0b0a68..1cb9e1e8f7 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -62,9 +62,9 @@ #include "nvim/path.h" #include "nvim/strings.h" #include "nvim/tag.h" -#include "nvim/ui.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" #include "nvim/os/fs_defs.h" static char_u *ff_expand_buffer = NULL; /* used for expanding filenames */ @@ -607,7 +607,7 @@ char_u *vim_findfile(void *search_ctx_arg) /* downward search loop */ for (;; ) { /* check if user user wants to stop the search*/ - ui_breakcheck(); + os_breakcheck(); if (got_int) break; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 97a357bff7..3be9d89d87 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -53,10 +53,11 @@ #include "nvim/tempfile.h" #include "nvim/term.h" #include "nvim/types.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/time.h" +#include "nvim/os/input.h" #if defined(HAVE_UTIME) && defined(HAVE_UTIME_H) # include <utime.h> /* for struct utimbuf */ @@ -1704,7 +1705,7 @@ rewind_retry: } } linerest = (long)(ptr - line_start); - ui_breakcheck(); + os_breakcheck(); } failed: @@ -2927,7 +2928,7 @@ buf_write ( "E506: Can't write to backup file (add ! to override)"); break; } - ui_breakcheck(); + os_breakcheck(); if (got_int) { errmsg = (char_u *)_(e_interr); break; @@ -3377,7 +3378,7 @@ restore_backup: s = buffer; len = 0; - ui_breakcheck(); + os_breakcheck(); if (got_int) { end = 0; /* Interrupted, break loop */ break; @@ -4958,7 +4959,7 @@ buf_check_timestamp ( if (emsg_silent == 0) { out_flush(); /* give the user some time to think about it */ - ui_delay(1000L, true); + os_delay(1000L, true); /* don't redraw and erase the message */ redraw_cmdline = FALSE; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 1bec0fa1bb..6c70773fcf 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -47,7 +47,6 @@ #include "nvim/screen.h" #include "nvim/strings.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/os/event.h" #include "nvim/os/input.h" @@ -1702,14 +1701,14 @@ static int vgetorpeek(int advance) */ for (;; ) { /* - * ui_breakcheck() is slow, don't use it too often when + * os_breakcheck() is slow, don't use it too often when * inside a mapping. But call it each time for typed * characters. */ if (typebuf.tb_maplen) line_breakcheck(); else - ui_breakcheck(); /* check for CTRL-C */ + os_breakcheck(); /* check for CTRL-C */ keylen = 0; if (got_int) { /* flush all input */ @@ -2481,7 +2480,7 @@ inchar ( char_u dum[DUM_LEN + 1]; for (;; ) { - len = ui_inchar(dum, DUM_LEN, 0L, 0); + len = os_inchar(dum, DUM_LEN, 0L, 0); if (len == 0 || (len == 1 && dum[0] == 3)) break; } @@ -2498,7 +2497,7 @@ inchar ( * Fill up to a third of the buffer, because each character may be * tripled below. */ - len = ui_inchar(buf, maxlen / 3, wait_time, tb_change_cnt); + len = os_inchar(buf, maxlen / 3, wait_time, tb_change_cnt); } if (typebuf_changed(tb_change_cnt)) diff --git a/src/nvim/globals.h b/src/nvim/globals.h index cd9f7a648f..2d8e511ade 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -855,7 +855,6 @@ EXTERN char_u *exe_name; /* the name of the executable */ EXTERN int dont_scroll INIT(= FALSE); /* don't use scrollbars when TRUE */ #endif EXTERN int mapped_ctrl_c INIT(= FALSE); /* CTRL-C is mapped */ -EXTERN bool ctrl_c_interrupts INIT(= true); /* CTRL-C sets got_int */ EXTERN cmdmod_T cmdmod; /* Ex command modifiers */ diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 1d15e30921..5d9d353fc8 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -41,8 +41,8 @@ #include "nvim/syntax.h" #include "nvim/term.h" #include "nvim/tempfile.h" -#include "nvim/ui.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" /* * To implement printing on a platform, the following functions must be @@ -724,7 +724,7 @@ void ex_hardcopy(exarg_T *eap) */ /* Check for interrupt character every page. */ - ui_breakcheck(); + os_breakcheck(); if (got_int || settings.user_abort) goto print_fail; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 667e6512f3..bb41db6168 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -29,9 +29,9 @@ #include "nvim/strings.h" #include "nvim/tag.h" #include "nvim/tempfile.h" -#include "nvim/ui.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" #include <sys/types.h> #include <sys/stat.h> @@ -1735,7 +1735,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) if (msg_col) msg_putchar('\n'); - ui_breakcheck(); + os_breakcheck(); if (got_int) { got_int = FALSE; /* don't print any more matches */ break; diff --git a/src/nvim/main.c b/src/nvim/main.c index 4447c404d5..68ae000c35 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -57,6 +57,7 @@ #include "nvim/ui.h" #include "nvim/version.h" #include "nvim/window.h" +#include "nvim/os/time.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/signal.h" @@ -1608,7 +1609,7 @@ static void check_tty(mparm_T *parmp) mch_errmsg(_("Vim: Warning: Input is not from a terminal\n")); out_flush(); if (scriptin[0] == NULL) - ui_delay(2000L, true); + os_delay(2000L, true); TIME_MSG("Warning delay"); } } @@ -1742,7 +1743,7 @@ static void create_windows(mparm_T *parmp) #endif dorewind = TRUE; /* start again */ } - ui_breakcheck(); + os_breakcheck(); if (got_int) { (void)vgetc(); /* only break the file loading, not the rest */ break; @@ -1832,7 +1833,7 @@ static void edit_buffers(mparm_T *parmp) arg_had_last = TRUE; ++arg_idx; } - ui_breakcheck(); + os_breakcheck(); if (got_int) { (void)vgetc(); /* only break the file loading, not the rest */ break; diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 120645cfe6..4ded438f52 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -38,8 +38,8 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" /* * This file contains routines to maintain and manipulate marks. @@ -811,7 +811,7 @@ void ex_jumps(exarg_T *eap) curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum ? hl_attr(HLF_D) : 0); free(name); - ui_breakcheck(); + os_breakcheck(); } out_flush(); } @@ -845,7 +845,7 @@ void ex_changes(exarg_T *eap) name = mark_line(&curbuf->b_changelist[i], 17); msg_outtrans_attr(name, hl_attr(HLF_D)); free(name); - ui_breakcheck(); + os_breakcheck(); } out_flush(); } diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 1656acb689..d8d59474a2 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -61,8 +61,8 @@ #include "nvim/memory.h" #include "nvim/os_unix.h" #include "nvim/path.h" -#include "nvim/ui.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" #define MEMFILE_PAGE_SIZE 4096 /// default page size @@ -455,10 +455,10 @@ int mf_sync(memfile_T *mfp, int flags) status = FAIL; } if (flags & MFS_STOP) { // Stop when char available now. - if (ui_char_avail()) + if (os_char_avail()) break; } else { - ui_breakcheck(); + os_breakcheck(); } if (got_int) break; diff --git a/src/nvim/memline.c b/src/nvim/memline.c index e9edeb842f..f6246c8b57 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -71,10 +71,10 @@ #include "nvim/strings.h" #include "nvim/term.h" #include "nvim/tempfile.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" #ifndef UNIX /* it's in os_unix_defs.h for Unix */ # include <time.h> @@ -1642,7 +1642,7 @@ void ml_sync_all(int check_file, int check_char) if (buf->b_ml.ml_mfp->mf_dirty) { (void)mf_sync(buf->b_ml.ml_mfp, (check_char ? MFS_STOP : 0) | (bufIsChanged(buf) ? MFS_FLUSH : 0)); - if (check_char && ui_char_avail()) /* character available now */ + if (check_char && os_char_avail()) /* character available now */ break; } } diff --git a/src/nvim/memory.c b/src/nvim/memory.c index f305c4628f..4c5a45b8b6 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -430,7 +430,6 @@ void do_outofmem_msg(size_t size) #include "nvim/spell.h" #include "nvim/syntax.h" #include "nvim/tag.h" -#include "nvim/ui.h" #include "nvim/window.h" #include "nvim/os/os.h" diff --git a/src/nvim/message.c b/src/nvim/message.c index 23feeab173..cd0c548fb4 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -42,8 +42,10 @@ #include "nvim/screen.h" #include "nvim/strings.h" #include "nvim/term.h" -#include "nvim/ui.h" +#include "nvim/mouse.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" +#include "nvim/os/time.h" /* * To be able to scroll back at the "more" and "hit-enter" prompts we need to @@ -877,7 +879,7 @@ void wait_return(int redraw) || c == K_X1MOUSE || c == K_X2MOUSE)) ); - ui_breakcheck(); + os_breakcheck(); /* * Avoid that the mouse-up event causes visual mode to start. */ @@ -2702,11 +2704,9 @@ do_dialog ( int c; int i; -#ifndef NO_CONSOLE /* Don't output anything in silent mode ("ex -s") */ if (silent_mode) return dfltbutton; /* return default option */ -#endif oldState = State; diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 310cb6faac..230e198121 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -58,6 +58,8 @@ #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/shell.h" +#include "nvim/os/input.h" +#include "nvim/os/time.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "misc1.c.generated.h" @@ -1840,7 +1842,7 @@ void changed(void) * and don't let the emsg() set msg_scroll. */ if (need_wait_return && emsg_silent == 0) { out_flush(); - ui_delay(2000L, true); + os_delay(2000L, true); wait_return(TRUE); msg_scroll = save_msg_scroll; } @@ -2261,7 +2263,7 @@ change_warning ( (void)msg_end(); if (msg_silent == 0 && !silent_mode) { out_flush(); - ui_delay(1000L, true); /* give the user time to think about it */ + os_delay(1000L, true); /* give the user time to think about it */ } curbuf->b_did_warn = true; redraw_cmdline = FALSE; /* don't redraw and erase the message */ @@ -2383,7 +2385,7 @@ int get_keystroke(void) /* First time: blocking wait. Second time: wait up to 100ms for a * terminal code to complete. */ - n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0); + n = os_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0); if (n > 0) { /* Replace zero and CSI by a special key code. */ n = fix_input_buffer(buf + len, n, FALSE); @@ -3362,8 +3364,8 @@ void preserve_exit(void) /* * Check for CTRL-C pressed, but only once in a while. - * Should be used instead of ui_breakcheck() for functions that check for - * each line in the file. Calling ui_breakcheck() each time takes too much + * Should be used instead of os_breakcheck() for functions that check for + * each line in the file. Calling os_breakcheck() each time takes too much * time, because it can be a system call. */ @@ -3377,7 +3379,7 @@ void line_breakcheck(void) { if (++breakcheck_count >= BREAKCHECK_SKIP) { breakcheck_count = 0; - ui_breakcheck(); + os_breakcheck(); } } @@ -3388,7 +3390,7 @@ void fast_breakcheck(void) { if (++breakcheck_count >= BREAKCHECK_SKIP * 10) { breakcheck_count = 0; - ui_breakcheck(); + os_breakcheck(); } } diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index 3fe5f1a0ed..acf243b349 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -50,7 +50,6 @@ #include "nvim/syntax.h" #include "nvim/tag.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/shell.h" diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c new file mode 100644 index 0000000000..7fc581a7c0 --- /dev/null +++ b/src/nvim/mouse.c @@ -0,0 +1,438 @@ +#include <stdbool.h> + +#include "nvim/mouse.h" +#include "nvim/vim.h" +#include "nvim/screen.h" +#include "nvim/window.h" +#include "nvim/term.h" +#include "nvim/fold.h" +#include "nvim/diff.h" +#include "nvim/move.h" +#include "nvim/misc1.h" +#include "nvim/cursor.h" +#include "nvim/buffer_defs.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "mouse.c.generated.h" +#endif + +// Move the cursor to the specified row and column on the screen. +// Change current window if necessary. Returns an integer with the +// CURSOR_MOVED bit set if the cursor has moved or unset otherwise. +// +// The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column. +// The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column. +// +// If flags has MOUSE_FOCUS, then the current window will not be changed, and +// if the mouse is outside the window then the text will scroll, or if the +// mouse was previously on a status line, then the status line may be dragged. +// +// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the +// cursor is moved unless the cursor was on a status line. +// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or +// IN_SEP_LINE depending on where the cursor was clicked. +// +// If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless +// the mouse is on the status line of the same window. +// +// If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since +// the last call. +// +// If flags has MOUSE_SETPOS, nothing is done, only the current position is +// remembered. +int jump_to_mouse(int flags, + bool *inclusive, // used for inclusive operator, can be NULL + int which_button) // MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE +{ + static int on_status_line = 0; // #lines below bottom of window + static int on_sep_line = 0; // on separator right of window + static int prev_row = -1; + static int prev_col = -1; + static win_T *dragwin = NULL; // window being dragged + static int did_drag = false; // drag was noticed + + win_T *wp, *old_curwin; + pos_T old_cursor; + int count; + bool first; + int row = mouse_row; + int col = mouse_col; + int mouse_char; + + mouse_past_bottom = false; + mouse_past_eol = false; + + if (flags & MOUSE_RELEASED) { + // On button release we may change window focus if positioned on a + // status line and no dragging happened. + if (dragwin != NULL && !did_drag) + flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE); + dragwin = NULL; + did_drag = false; + } + + if ((flags & MOUSE_DID_MOVE) + && prev_row == mouse_row + && prev_col == mouse_col) { +retnomove: + // before moving the cursor for a left click which is NOT in a status + // line, stop Visual mode + if (on_status_line) + return IN_STATUS_LINE; + if (on_sep_line) + return IN_SEP_LINE; + if (flags & MOUSE_MAY_STOP_VIS) { + end_visual_mode(); + redraw_curbuf_later(INVERTED); // delete the inversion + } + return IN_BUFFER; + } + + prev_row = mouse_row; + prev_col = mouse_col; + + if (flags & MOUSE_SETPOS) + goto retnomove; // ugly goto... + + // Remember the character under the mouse, it might be a '-' or '+' in the + // fold column. + if (row >= 0 && row < Rows && col >= 0 && col <= Columns + && ScreenLines != NULL) + mouse_char = ScreenLines[LineOffset[row] + (unsigned)col]; + else + mouse_char = ' '; + + old_curwin = curwin; + old_cursor = curwin->w_cursor; + + if (!(flags & MOUSE_FOCUS)) { + if (row < 0 || col < 0) // check if it makes sense + return IN_UNKNOWN; + + // find the window where the row is in + wp = mouse_find_win(&row, &col); + dragwin = NULL; + // winpos and height may change in win_enter()! + if (row >= wp->w_height) { // In (or below) status line + on_status_line = row - wp->w_height + 1; + dragwin = wp; + } else { + on_status_line = 0; + } + + if (col >= wp->w_width) { // In separator line + on_sep_line = col - wp->w_width + 1; + dragwin = wp; + } else { + on_sep_line = 0; + } + + // The rightmost character of the status line might be a vertical + // separator character if there is no connecting window to the right. + if (on_status_line && on_sep_line) { + if (stl_connected(wp)) + on_sep_line = 0; + else + on_status_line = 0; + } + + // Before jumping to another buffer, or moving the cursor for a left + // click, stop Visual mode. + if (VIsual_active + && (wp->w_buffer != curwin->w_buffer + || (!on_status_line + && !on_sep_line + && ( + wp->w_p_rl ? col < wp->w_width - wp->w_p_fdc : + col >= wp->w_p_fdc + + (cmdwin_type == 0 && wp == + curwin ? 0 : 1) + ) + && (flags & MOUSE_MAY_STOP_VIS)))) { + end_visual_mode(); + redraw_curbuf_later(INVERTED); // delete the inversion + } + if (cmdwin_type != 0 && wp != curwin) { + // A click outside the command-line window: Use modeless + // selection if possible. Allow dragging the status lines. + on_sep_line = 0; + row = 0; + col += wp->w_wincol; + wp = curwin; + } + // Only change window focus when not clicking on or dragging the + // status line. Do change focus when releasing the mouse button + // (MOUSE_FOCUS was set above if we dragged first). + if (dragwin == NULL || (flags & MOUSE_RELEASED)) + win_enter(wp, true); // can make wp invalid! +# ifdef CHECK_DOUBLE_CLICK + // set topline, to be able to check for double click ourselves + if (curwin != old_curwin) + set_mouse_topline(curwin); +# endif + if (on_status_line) { // In (or below) status line + // Don't use start_arrow() if we're in the same window + if (curwin == old_curwin) + return IN_STATUS_LINE; + else + return IN_STATUS_LINE | CURSOR_MOVED; + } + if (on_sep_line) { // In (or below) status line + // Don't use start_arrow() if we're in the same window + if (curwin == old_curwin) + return IN_SEP_LINE; + else + return IN_SEP_LINE | CURSOR_MOVED; + } + + curwin->w_cursor.lnum = curwin->w_topline; + } else if (on_status_line && which_button == MOUSE_LEFT) { + if (dragwin != NULL) { + // Drag the status line + count = row - dragwin->w_winrow - dragwin->w_height + 1 + - on_status_line; + win_drag_status_line(dragwin, count); + did_drag |= count; + } + return IN_STATUS_LINE; // Cursor didn't move + } else if (on_sep_line && which_button == MOUSE_LEFT) { + if (dragwin != NULL) { + // Drag the separator column + count = col - dragwin->w_wincol - dragwin->w_width + 1 + - on_sep_line; + win_drag_vsep_line(dragwin, count); + did_drag |= count; + } + return IN_SEP_LINE; // Cursor didn't move + } else { + // keep_window_focus must be true + // before moving the cursor for a left click, stop Visual mode + if (flags & MOUSE_MAY_STOP_VIS) { + end_visual_mode(); + redraw_curbuf_later(INVERTED); // delete the inversion + } + + + row -= curwin->w_winrow; + col -= curwin->w_wincol; + + // When clicking beyond the end of the window, scroll the screen. + // Scroll by however many rows outside the window we are. + if (row < 0) { + count = 0; + for (first = true; curwin->w_topline > 1; ) { + if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) + ++count; + else + count += plines(curwin->w_topline - 1); + if (!first && count > -row) + break; + first = false; + hasFolding(curwin->w_topline, &curwin->w_topline, NULL); + if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) { + ++curwin->w_topfill; + } else { + --curwin->w_topline; + curwin->w_topfill = 0; + } + } + check_topfill(curwin, false); + curwin->w_valid &= + ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); + redraw_later(VALID); + row = 0; + } else if (row >= curwin->w_height) { + count = 0; + for (first = true; curwin->w_topline < curbuf->b_ml.ml_line_count; ) { + if (curwin->w_topfill > 0) { + ++count; + } else { + count += plines(curwin->w_topline); + } + + if (!first && count > row - curwin->w_height + 1) { + break; + } + first = false; + + if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline) + && curwin->w_topline == curbuf->b_ml.ml_line_count) { + break; + } + + if (curwin->w_topfill > 0) { + --curwin->w_topfill; + } else { + ++curwin->w_topline; + curwin->w_topfill = + diff_check_fill(curwin, curwin->w_topline); + } + } + check_topfill(curwin, false); + redraw_later(VALID); + curwin->w_valid &= + ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); + row = curwin->w_height - 1; + } else if (row == 0) { + // When dragging the mouse, while the text has been scrolled up as + // far as it goes, moving the mouse in the top line should scroll + // the text down (done later when recomputing w_topline). + if (mouse_dragging > 0 + && curwin->w_cursor.lnum + == curwin->w_buffer->b_ml.ml_line_count + && curwin->w_cursor.lnum == curwin->w_topline) { + curwin->w_valid &= ~(VALID_TOPLINE); + } + } + } + + // Check for position outside of the fold column. + if (curwin->w_p_rl ? col < curwin->w_width - curwin->w_p_fdc : + col >= curwin->w_p_fdc + (cmdwin_type == 0 ? 0 : 1)) { + mouse_char = ' '; + } + + // compute the position in the buffer line from the posn on the screen + if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum)) { + mouse_past_bottom = true; + } + + // Start Visual mode before coladvance(), for when 'sel' != "old" + if ((flags & MOUSE_MAY_VIS) && !VIsual_active) { + check_visual_highlight(); + VIsual = old_cursor; + VIsual_active = true; + VIsual_reselect = true; + // if 'selectmode' contains "mouse", start Select mode + may_start_select('o'); + setmouse(); + + if (p_smd && msg_silent == 0) { + redraw_cmdline = true; // show visual mode later + } + } + + curwin->w_curswant = col; + curwin->w_set_curswant = false; // May still have been true + if (coladvance(col) == FAIL) { // Mouse click beyond end of line + if (inclusive != NULL) { + *inclusive = true; + } + mouse_past_eol = true; + } else if (inclusive != NULL) { + *inclusive = false; + } + + count = IN_BUFFER; + if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum + || curwin->w_cursor.col != old_cursor.col) { + count |= CURSOR_MOVED; // Cursor has moved + } + + if (mouse_char == '+') { + count |= MOUSE_FOLD_OPEN; + } else if (mouse_char != ' ') { + count |= MOUSE_FOLD_CLOSE; + } + + return count; +} + +// Compute the position in the buffer line from the posn on the screen in +// window "win". +// Returns true if the position is below the last line. +bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump) +{ + int col = *colp; + int row = *rowp; + linenr_T lnum; + bool retval = false; + int off; + int count; + + if (win->w_p_rl) + col = win->w_width - 1 - col; + + lnum = win->w_topline; + + while (row > 0) { + // Don't include filler lines in "count" + if (win->w_p_diff + && !hasFoldingWin(win, lnum, NULL, NULL, true, NULL)) { + if (lnum == win->w_topline) { + row -= win->w_topfill; + } else { + row -= diff_check_fill(win, lnum); + } + count = plines_win_nofill(win, lnum, true); + } else { + count = plines_win(win, lnum, true); + } + + if (count > row) { + break; // Position is in this buffer line. + } + + (void)hasFoldingWin(win, lnum, NULL, &lnum, true, NULL); + + if (lnum == win->w_buffer->b_ml.ml_line_count) { + retval = true; + break; // past end of file + } + row -= count; + ++lnum; + } + + if (!retval) { + // Compute the column without wrapping. + off = win_col_off(win) - win_col_off2(win); + if (col < off) + col = off; + col += row * (win->w_width - off); + // add skip column (for long wrapping line) + col += win->w_skipcol; + } + + if (!win->w_p_wrap) { + col += win->w_leftcol; + } + + // skip line number and fold column in front of the line + col -= win_col_off(win); + if (col < 0) { + col = 0; + } + + *colp = col; + *rowp = row; + *lnump = lnum; + return retval; +} + +// Find the window at screen position "*rowp" and "*colp". The positions are +// updated to become relative to the top-left of the window. +win_T *mouse_find_win(int *rowp, int *colp) +{ + frame_T *fp; + + fp = topframe; + *rowp -= firstwin->w_winrow; + for (;; ) { + if (fp->fr_layout == FR_LEAF) + break; + if (fp->fr_layout == FR_ROW) { + for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) { + if (*colp < fp->fr_width) + break; + *colp -= fp->fr_width; + } + } else { // fr_layout == FR_COL + for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) { + if (*rowp < fp->fr_height) + break; + *rowp -= fp->fr_height; + } + } + } + return fp->fr_win; +} diff --git a/src/nvim/mouse.h b/src/nvim/mouse.h new file mode 100644 index 0000000000..4f797c7480 --- /dev/null +++ b/src/nvim/mouse.h @@ -0,0 +1,32 @@ +#ifndef NVIM_MOUSE_H +#define NVIM_MOUSE_H + +#include <stdbool.h> + +#include "nvim/vim.h" +#include "nvim/buffer_defs.h" + +// jump_to_mouse() returns one of first four these values, possibly with +// some of the other three added. +#define IN_UNKNOWN 0 +#define IN_BUFFER 1 +#define IN_STATUS_LINE 2 // on status or command line +#define IN_SEP_LINE 4 // on vertical separator line +#define IN_OTHER_WIN 8 // in other window but can't go there +#define CURSOR_MOVED 0x100 +#define MOUSE_FOLD_CLOSE 0x200 // clicked on '-' in fold column +#define MOUSE_FOLD_OPEN 0x400 // clicked on '+' in fold column + +// flags for jump_to_mouse() +#define MOUSE_FOCUS 0x01 // need to stay in this window +#define MOUSE_MAY_VIS 0x02 // may start Visual mode +#define MOUSE_DID_MOVE 0x04 // only act when mouse has moved +#define MOUSE_SETPOS 0x08 // only set current mouse position +#define MOUSE_MAY_STOP_VIS 0x10 // may stop Visual mode +#define MOUSE_RELEASED 0x20 // button was released + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "mouse.h.generated.h" +#endif + +#endif // NVIM_MOUSE_H diff --git a/src/nvim/normal.c b/src/nvim/normal.c index f58e044c2c..5202354199 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -57,9 +57,11 @@ #include "nvim/tag.h" #include "nvim/term.h" #include "nvim/ui.h" +#include "nvim/mouse.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/event.h" +#include "nvim/os/time.h" /* * The Visual area is remembered for reselection. @@ -1008,8 +1010,8 @@ getcount: cursor_on(); out_flush(); if (msg_scroll || emsg_on_display) - ui_delay(1000L, true); /* wait at least one second */ - ui_delay(3000L, false); /* wait up to three seconds */ + os_delay(1000L, true); /* wait at least one second */ + os_delay(3000L, false); /* wait up to three seconds */ State = save_State; msg_scroll = false; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 5ef605bb3b..6bf3f6036f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -45,10 +45,9 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" -#include "nvim/api/private/helpers.h" +#include "nvim/os/input.h" /* * Registers: @@ -1112,7 +1111,7 @@ insert_reg ( * register a and then, in insert mode, doing CTRL-R a. * If you hit CTRL-C, the loop will be broken here. */ - ui_breakcheck(); + os_breakcheck(); if (got_int) return FAIL; @@ -1296,7 +1295,7 @@ cmdline_paste_reg ( /* Check for CTRL-C, in case someone tries to paste a few thousand * lines and gets bored. */ - ui_breakcheck(); + os_breakcheck(); if (got_int) return FAIL; } @@ -3254,7 +3253,7 @@ void ex_display(exarg_T *eap) MSG_PUTS_ATTR("^J", attr); out_flush(); /* show one line at a time */ } - ui_breakcheck(); + os_breakcheck(); } /* @@ -3339,7 +3338,7 @@ dis_msg ( } else msg_outtrans_len(p++, 1); } - ui_breakcheck(); + os_breakcheck(); } /* @@ -5079,7 +5078,7 @@ void cursor_pos_info(void) for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { /* Check for a CTRL-C every 100000 characters. */ if (byte_count > last_check) { - ui_breakcheck(); + os_breakcheck(); if (got_int) return; last_check = byte_count + 100000L; diff --git a/src/nvim/option.c b/src/nvim/option.c index 830a30204b..1d3281e952 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -75,10 +75,10 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" /* * The options that are local to a window or buffer have "indir" set to one of @@ -6123,7 +6123,7 @@ showoptions ( col += INC; } out_flush(); - ui_breakcheck(); + os_breakcheck(); } } free(items); diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index d10d20b20e..686fe1f06d 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -17,8 +17,11 @@ #include "nvim/keymap.h" #include "nvim/mbyte.h" #include "nvim/fileio.h" +#include "nvim/ex_cmds2.h" #include "nvim/getchar.h" #include "nvim/term.h" +#include "nvim/main.h" +#include "nvim/misc1.h" #define READ_BUFFER_SIZE 0xfff #define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4) @@ -184,7 +187,16 @@ size_t input_enqueue(String keys) static bool input_poll(int ms) { + if (do_profiling == PROF_YES && ms) { + prof_inchar_enter(); + } + event_poll_until(ms, input_ready()); + + if (do_profiling == PROF_YES && ms) { + prof_inchar_exit(); + } + return input_ready(); } @@ -282,7 +294,7 @@ static void convert_input(void) static void process_interrupts(void) { - if (!ctrl_c_interrupts) { + if (mapped_ctrl_c) { return; } @@ -326,3 +338,11 @@ static bool input_ready(void) (!embedded_mode && eof); // Stdin closed } +// Exit because of an input read error. +static void read_error_exit(void) +{ + if (silent_mode) /* Normal way to exit for "ex -s" */ + getout(0); + STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); + preserve_exit(); +} diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 8ab61045dc..3bf1198b46 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -46,7 +46,6 @@ #include "nvim/tempfile.h" #include "nvim/term.h" #include "nvim/types.h" -#include "nvim/ui.h" #include "nvim/os/os.h" #include "nvim/os/time.h" #include "nvim/os/event.h" diff --git a/src/nvim/path.c b/src/nvim/path.c index ff97b7774a..e8d31f3f73 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -31,7 +31,7 @@ #include "nvim/strings.h" #include "nvim/tag.h" #include "nvim/types.h" -#include "nvim/ui.h" +#include "nvim/os/input.h" #include "nvim/window.h" #define URL_SLASH 1 /* path_is_url() has found "://" */ @@ -449,7 +449,7 @@ unix_expandpath ( /* Expanding "**" may take a long time, check for CTRL-C. */ if (stardepth > 0) { - ui_breakcheck(); + os_breakcheck(); if (got_int) return 0; } @@ -850,7 +850,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) STRMOVE(path + STRLEN(path), short_name); } } - ui_breakcheck(); + os_breakcheck(); } /* Shorten filenames in /in/current/directory/{filename} */ @@ -879,7 +879,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) free(fnames[i]); fnames[i] = rel_path; sort_again = TRUE; - ui_breakcheck(); + os_breakcheck(); } free(curdir); diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 3de7f73339..4baba00ccf 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -49,9 +49,9 @@ #include "nvim/strings.h" #include "nvim/term.h" #include "nvim/tempfile.h" -#include "nvim/ui.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" struct dir_stack_T { @@ -1791,7 +1791,7 @@ void qf_list(exarg_T *eap) qfp = qfp->qf_next; ++i; - ui_breakcheck(); + os_breakcheck(); } } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 3cbdbdd81f..bb26066526 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -129,10 +129,10 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" +#include "nvim/os/time.h" #define MB_FILLER_CHAR '<' /* character used when a double-width character * doesn't fit. */ @@ -6255,7 +6255,7 @@ void check_for_delay(int check_msg_scroll) && !did_wait_return && emsg_silent == 0) { out_flush(); - ui_delay(1000L, true); + os_delay(1000L, true); emsg_on_display = FALSE; if (check_msg_scroll) msg_scroll = FALSE; diff --git a/src/nvim/search.c b/src/nvim/search.c index bd1811c7fb..78d9dcbccb 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -48,6 +48,7 @@ #include "nvim/term.h" #include "nvim/ui.h" #include "nvim/window.h" +#include "nvim/os/time.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -2053,9 +2054,9 @@ showmatch ( * available. */ if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL) - ui_delay(p_mat * 100L, true); + os_delay(p_mat * 100L, true); else if (!char_avail()) - ui_delay(p_mat * 100L, false); + os_delay(p_mat * 100L, false); curwin->w_cursor = save_cursor; /* restore cursor position */ p_so = save_so; p_siso = save_siso; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index ea5ce7ee0d..fa786fdd74 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -325,9 +325,9 @@ #include "nvim/syntax.h" #include "nvim/term.h" #include "nvim/tempfile.h" -#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/os/os.h" +#include "nvim/os/input.h" #ifndef UNIX // it's in os_unix_defs.h for Unix # include <time.h> // for time_t @@ -9018,7 +9018,7 @@ static void spell_suggest_intern(suginfo_T *su, bool interactive) // When CTRL-C was hit while searching do show the results. Only clear // got_int when using a command, not for spellsuggest(). - ui_breakcheck(); + os_breakcheck(); if (interactive && got_int) { (void)vgetc(); got_int = FALSE; @@ -10616,7 +10616,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Don't check for CTRL-C too often, it takes time. if (--breakcheckcount == 0) { - ui_breakcheck(); + os_breakcheck(); breakcheckcount = 1000; } } diff --git a/src/nvim/strings.c b/src/nvim/strings.c index d34014ac75..6c69b3b34a 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -42,7 +42,6 @@ #include "nvim/syntax.h" #include "nvim/tag.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/shell.h" diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6c5c0f37b1..69d6479cf3 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -44,8 +44,8 @@ #include "nvim/strings.h" #include "nvim/syntax_defs.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/os/os.h" +#include "nvim/os/time.h" /* * Structure that stores information about a highlight group. @@ -7606,7 +7606,7 @@ static void highlight_list_two(int cnt, int attr) msg_puts_attr((char_u *)&("N \bI \b! \b"[cnt / 11]), attr); msg_clr_eos(); out_flush(); - ui_delay(cnt == 99 ? 40L : (long)cnt * 50L, false); + os_delay(cnt == 99 ? 40L : (long)cnt * 50L, false); } diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 6ac6dc5cd2..fb39e069f0 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -49,9 +49,10 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/term.h" -#include "nvim/ui.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/os/time.h" +#include "nvim/os/input.h" /* * Structure to hold pointers to various items in a tag line. @@ -672,7 +673,7 @@ do_tag ( } if (msg_col) msg_putchar('\n'); - ui_breakcheck(); + os_breakcheck(); } if (got_int) got_int = FALSE; /* only stop the listing */ @@ -881,7 +882,7 @@ do_tag ( give_warning(IObuff, ic); if (ic && !msg_scrolled && msg_silent == 0) { out_flush(); - ui_delay(1000L, true); + os_delay(1000L, true); } } @@ -2493,7 +2494,7 @@ jumpto_tag ( MSG(_("E435: Couldn't find tag, just guessing!")); if (!msg_scrolled && msg_silent == 0) { out_flush(); - ui_delay(1000L, true); + os_delay(1000L, true); } } retval = OK; diff --git a/src/nvim/term.c b/src/nvim/term.c index 263b81fc3a..3d1053bd2f 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -54,6 +54,7 @@ #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/time.h" +#include "nvim/os/input.h" #ifdef HAVE_TGETENT # ifdef HAVE_TERMIOS_H @@ -1330,7 +1331,7 @@ int set_termname(char_u *term) if (emsg_silent == 0) { screen_start(); /* don't know where cursor is now */ out_flush(); - ui_delay(2000L, true); + os_delay(2000L, true); } set_string_option_direct((char_u *)"term", -1, term, OPT_FREE, 0); @@ -2302,7 +2303,7 @@ void set_shellsize(int width, int height, int mustset) Rows = height; Columns = width; check_shellsize(); - ui_set_shellsize(mustset); + mch_set_shellsize(); } else check_shellsize(); @@ -4111,7 +4112,7 @@ void show_termcodes(void) col += INC3; } out_flush(); - ui_breakcheck(); + os_breakcheck(); } } free(items); diff --git a/src/nvim/ui.c b/src/nvim/ui.c index d6269897d7..803e7fab50 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -44,7 +44,6 @@ void ui_write(char_u *s, int len) { -#ifndef NO_CONSOLE /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ if (!(silent_mode && p_verbose == 0)) { char_u *tofree = NULL; @@ -61,112 +60,6 @@ void ui_write(char_u *s, int len) if (output_conv.vc_type != CONV_NONE) free(tofree); } -#endif -} - -/* - * ui_inchar(): low level input function. - * Get characters from the keyboard. - * Return the number of characters that are available. - * If "wtime" == 0 do not wait for characters. - * If "wtime" == -1 wait forever for characters. - * If "wtime" > 0 wait "wtime" milliseconds for a character. - * - * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into - * it. When typebuf.tb_change_cnt changes (e.g., when a message is received - * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL - * otherwise. - */ -int -ui_inchar ( - char_u *buf, - int maxlen, - long wtime, /* don't use "time", MIPS cannot handle it */ - int tb_change_cnt -) -{ - int retval = 0; - - - if (do_profiling == PROF_YES && wtime != 0) - prof_inchar_enter(); - -#ifdef NO_CONSOLE_INPUT - /* Don't wait for character input when the window hasn't been opened yet. - * Do try reading, this works when redirecting stdin from a file. - * Must return something, otherwise we'll loop forever. If we run into - * this very often we probably got stuck, exit Vim. */ - if (no_console_input()) { - static int count = 0; - -# ifndef NO_CONSOLE - retval = os_inchar(buf, maxlen, (wtime >= 0 && wtime < 10) - ? 10L : wtime, tb_change_cnt); - if (retval > 0 || typebuf_changed(tb_change_cnt) || wtime >= 0) - goto theend; -# endif - if (wtime == -1 && ++count == 1000) - read_error_exit(); - buf[0] = CAR; - retval = 1; - goto theend; - } -#endif - - /* If we are going to wait for some time or block... */ - if (wtime == -1 || wtime > 100L) { - /* ... allow signals to kill us. */ - signal_accept_deadly(); - - /* ... there is no need for CTRL-C to interrupt something, don't let - * it set got_int when it was mapped. */ - if (mapped_ctrl_c) - ctrl_c_interrupts = false; - } - -#ifndef NO_CONSOLE - { - retval = os_inchar(buf, maxlen, wtime, tb_change_cnt); - } -#endif - - if (wtime == -1 || wtime > 100L) - /* block SIGHUP et al. */ - signal_reject_deadly(); - - ctrl_c_interrupts = true; - -#ifdef NO_CONSOLE_INPUT -theend: -#endif - if (do_profiling == PROF_YES && wtime != 0) - prof_inchar_exit(); - return retval; -} - -/* - * return non-zero if a character is available - */ -int ui_char_avail(void) -{ -#ifndef NO_CONSOLE -# ifdef NO_CONSOLE_INPUT - if (no_console_input()) - return 0; -# endif - return os_char_avail(); -#else - return 0; -#endif -} - -/* - * Delay for the given number of milliseconds. If ignoreinput is FALSE then we - * cancel the delay if a key is hit. - */ -void ui_delay(long msec, bool ignoreinput) -{ - os_delay(msec, ignoreinput); } /* @@ -201,52 +94,11 @@ int ui_get_shellsize(void) } /* - * Set the size of the Vim shell according to Rows and Columns, if possible. - * The gui_set_shellsize() or mch_set_shellsize() function will try to set the - * new size. If this is not possible, it will adjust Rows and Columns. - */ -void -ui_set_shellsize(int mustset) -{ - mch_set_shellsize(); -} - -void ui_breakcheck(void) -{ - os_breakcheck(); -} - -/***************************************************************************** - * Functions for copying and pasting text between applications. - * This is always included in a GUI version, but may also be included when the - * clipboard and mouse is available to a terminal version such as xterm. - * Note: there are some more functions in ops.c that handle selection stuff. - * - * Also note that the majority of functions here deal with the X 'primary' - * (visible - for Visual mode use) selection, and only that. There are no - * versions of these for the 'clipboard' selection, as Visual mode has no use - * for them. - */ - -/* - * Exit because of an input read error. - */ -void read_error_exit(void) -{ - if (silent_mode) /* Normal way to exit for "ex -s" */ - getout(0); - STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); - preserve_exit(); -} - -/* * May update the shape of the cursor. */ void ui_cursor_shape(void) { term_cursor_shape(); - - conceal_check_cursur_line(); } @@ -274,421 +126,6 @@ int check_row(int row) return row; } -/* - * Stuff for the X clipboard. Shared between VMS and Unix. - */ - -/* - * Move the cursor to the specified row and column on the screen. - * Change current window if necessary. Returns an integer with the - * CURSOR_MOVED bit set if the cursor has moved or unset otherwise. - * - * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column. - * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column. - * - * If flags has MOUSE_FOCUS, then the current window will not be changed, and - * if the mouse is outside the window then the text will scroll, or if the - * mouse was previously on a status line, then the status line may be dragged. - * - * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the - * cursor is moved unless the cursor was on a status line. - * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or - * IN_SEP_LINE depending on where the cursor was clicked. - * - * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless - * the mouse is on the status line of the same window. - * - * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since - * the last call. - * - * If flags has MOUSE_SETPOS, nothing is done, only the current position is - * remembered. - */ -int -jump_to_mouse ( - int flags, - bool *inclusive, /* used for inclusive operator, can be NULL */ - int which_button /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */ -) -{ - static int on_status_line = 0; /* #lines below bottom of window */ - static int on_sep_line = 0; /* on separator right of window */ - static int prev_row = -1; - static int prev_col = -1; - static win_T *dragwin = NULL; /* window being dragged */ - static int did_drag = FALSE; /* drag was noticed */ - - win_T *wp, *old_curwin; - pos_T old_cursor; - int count; - bool first; - int row = mouse_row; - int col = mouse_col; - int mouse_char; - - mouse_past_bottom = false; - mouse_past_eol = false; - - if (flags & MOUSE_RELEASED) { - /* On button release we may change window focus if positioned on a - * status line and no dragging happened. */ - if (dragwin != NULL && !did_drag) - flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE); - dragwin = NULL; - did_drag = FALSE; - } - - if ((flags & MOUSE_DID_MOVE) - && prev_row == mouse_row - && prev_col == mouse_col) { -retnomove: - /* before moving the cursor for a left click which is NOT in a status - * line, stop Visual mode */ - if (on_status_line) - return IN_STATUS_LINE; - if (on_sep_line) - return IN_SEP_LINE; - if (flags & MOUSE_MAY_STOP_VIS) { - end_visual_mode(); - redraw_curbuf_later(INVERTED); /* delete the inversion */ - } - return IN_BUFFER; - } - - prev_row = mouse_row; - prev_col = mouse_col; - - if (flags & MOUSE_SETPOS) - goto retnomove; /* ugly goto... */ - - /* Remember the character under the mouse, it might be a '-' or '+' in the - * fold column. */ - if (row >= 0 && row < Rows && col >= 0 && col <= Columns - && ScreenLines != NULL) - mouse_char = ScreenLines[LineOffset[row] + col]; - else - mouse_char = ' '; - - old_curwin = curwin; - old_cursor = curwin->w_cursor; - - if (!(flags & MOUSE_FOCUS)) { - if (row < 0 || col < 0) /* check if it makes sense */ - return IN_UNKNOWN; - - /* find the window where the row is in */ - wp = mouse_find_win(&row, &col); - dragwin = NULL; - /* - * winpos and height may change in win_enter()! - */ - if (row >= wp->w_height) { /* In (or below) status line */ - on_status_line = row - wp->w_height + 1; - dragwin = wp; - } else - on_status_line = 0; - if (col >= wp->w_width) { /* In separator line */ - on_sep_line = col - wp->w_width + 1; - dragwin = wp; - } else - on_sep_line = 0; - - /* The rightmost character of the status line might be a vertical - * separator character if there is no connecting window to the right. */ - if (on_status_line && on_sep_line) { - if (stl_connected(wp)) - on_sep_line = 0; - else - on_status_line = 0; - } - - /* Before jumping to another buffer, or moving the cursor for a left - * click, stop Visual mode. */ - if (VIsual_active - && (wp->w_buffer != curwin->w_buffer - || (!on_status_line - && !on_sep_line - && ( - wp->w_p_rl ? col < wp->w_width - wp->w_p_fdc : - col >= wp->w_p_fdc - + (cmdwin_type == 0 && wp == - curwin ? 0 : 1) - ) - && (flags & MOUSE_MAY_STOP_VIS)))) { - end_visual_mode(); - redraw_curbuf_later(INVERTED); /* delete the inversion */ - } - if (cmdwin_type != 0 && wp != curwin) { - /* A click outside the command-line window: Use modeless - * selection if possible. Allow dragging the status lines. */ - on_sep_line = 0; - row = 0; - col += wp->w_wincol; - wp = curwin; - } - /* Only change window focus when not clicking on or dragging the - * status line. Do change focus when releasing the mouse button - * (MOUSE_FOCUS was set above if we dragged first). */ - if (dragwin == NULL || (flags & MOUSE_RELEASED)) - win_enter(wp, true); /* can make wp invalid! */ -# ifdef CHECK_DOUBLE_CLICK - /* set topline, to be able to check for double click ourselves */ - if (curwin != old_curwin) - set_mouse_topline(curwin); -# endif - if (on_status_line) { /* In (or below) status line */ - /* Don't use start_arrow() if we're in the same window */ - if (curwin == old_curwin) - return IN_STATUS_LINE; - else - return IN_STATUS_LINE | CURSOR_MOVED; - } - if (on_sep_line) { /* In (or below) status line */ - /* Don't use start_arrow() if we're in the same window */ - if (curwin == old_curwin) - return IN_SEP_LINE; - else - return IN_SEP_LINE | CURSOR_MOVED; - } - - curwin->w_cursor.lnum = curwin->w_topline; - } else if (on_status_line && which_button == MOUSE_LEFT) { - if (dragwin != NULL) { - /* Drag the status line */ - count = row - dragwin->w_winrow - dragwin->w_height + 1 - - on_status_line; - win_drag_status_line(dragwin, count); - did_drag |= count; - } - return IN_STATUS_LINE; /* Cursor didn't move */ - } else if (on_sep_line && which_button == MOUSE_LEFT) { - if (dragwin != NULL) { - /* Drag the separator column */ - count = col - dragwin->w_wincol - dragwin->w_width + 1 - - on_sep_line; - win_drag_vsep_line(dragwin, count); - did_drag |= count; - } - return IN_SEP_LINE; /* Cursor didn't move */ - } else { /* keep_window_focus must be TRUE */ - /* before moving the cursor for a left click, stop Visual mode */ - if (flags & MOUSE_MAY_STOP_VIS) { - end_visual_mode(); - redraw_curbuf_later(INVERTED); /* delete the inversion */ - } - - - row -= curwin->w_winrow; - col -= curwin->w_wincol; - - /* - * When clicking beyond the end of the window, scroll the screen. - * Scroll by however many rows outside the window we are. - */ - if (row < 0) { - count = 0; - for (first = true; curwin->w_topline > 1; ) { - if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) - ++count; - else - count += plines(curwin->w_topline - 1); - if (!first && count > -row) - break; - first = false; - hasFolding(curwin->w_topline, &curwin->w_topline, NULL); - if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) - ++curwin->w_topfill; - else { - --curwin->w_topline; - curwin->w_topfill = 0; - } - } - check_topfill(curwin, false); - curwin->w_valid &= - ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); - redraw_later(VALID); - row = 0; - } else if (row >= curwin->w_height) { - count = 0; - for (first = true; curwin->w_topline < curbuf->b_ml.ml_line_count; ) { - if (curwin->w_topfill > 0) - ++count; - else - count += plines(curwin->w_topline); - if (!first && count > row - curwin->w_height + 1) - break; - first = false; - if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline) - && curwin->w_topline == curbuf->b_ml.ml_line_count) - break; - if (curwin->w_topfill > 0) - --curwin->w_topfill; - else { - ++curwin->w_topline; - curwin->w_topfill = - diff_check_fill(curwin, curwin->w_topline); - } - } - check_topfill(curwin, false); - redraw_later(VALID); - curwin->w_valid &= - ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); - row = curwin->w_height - 1; - } else if (row == 0) { - /* When dragging the mouse, while the text has been scrolled up as - * far as it goes, moving the mouse in the top line should scroll - * the text down (done later when recomputing w_topline). */ - if (mouse_dragging > 0 - && curwin->w_cursor.lnum - == curwin->w_buffer->b_ml.ml_line_count - && curwin->w_cursor.lnum == curwin->w_topline) - curwin->w_valid &= ~(VALID_TOPLINE); - } - } - - /* Check for position outside of the fold column. */ - if ( - curwin->w_p_rl ? col < curwin->w_width - curwin->w_p_fdc : - col >= curwin->w_p_fdc - + (cmdwin_type == 0 ? 0 : 1) - ) - mouse_char = ' '; - - /* compute the position in the buffer line from the posn on the screen */ - if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum)) - mouse_past_bottom = true; - - /* Start Visual mode before coladvance(), for when 'sel' != "old" */ - if ((flags & MOUSE_MAY_VIS) && !VIsual_active) { - check_visual_highlight(); - VIsual = old_cursor; - VIsual_active = TRUE; - VIsual_reselect = TRUE; - /* if 'selectmode' contains "mouse", start Select mode */ - may_start_select('o'); - setmouse(); - if (p_smd && msg_silent == 0) - redraw_cmdline = TRUE; /* show visual mode later */ - } - - curwin->w_curswant = col; - curwin->w_set_curswant = FALSE; /* May still have been TRUE */ - if (coladvance(col) == FAIL) { /* Mouse click beyond end of line */ - if (inclusive != NULL) - *inclusive = true; - mouse_past_eol = true; - } else if (inclusive != NULL) - *inclusive = false; - - count = IN_BUFFER; - if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum - || curwin->w_cursor.col != old_cursor.col) - count |= CURSOR_MOVED; /* Cursor has moved */ - - if (mouse_char == '+') - count |= MOUSE_FOLD_OPEN; - else if (mouse_char != ' ') - count |= MOUSE_FOLD_CLOSE; - - return count; -} - -/* - * Compute the position in the buffer line from the posn on the screen in - * window "win". - * Returns TRUE if the position is below the last line. - */ -bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump) -{ - int col = *colp; - int row = *rowp; - linenr_T lnum; - bool retval = false; - int off; - int count; - - if (win->w_p_rl) - col = win->w_width - 1 - col; - - lnum = win->w_topline; - - while (row > 0) { - /* Don't include filler lines in "count" */ - if (win->w_p_diff - && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL) - ) { - if (lnum == win->w_topline) - row -= win->w_topfill; - else - row -= diff_check_fill(win, lnum); - count = plines_win_nofill(win, lnum, TRUE); - } else - count = plines_win(win, lnum, TRUE); - if (count > row) - break; /* Position is in this buffer line. */ - (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL); - if (lnum == win->w_buffer->b_ml.ml_line_count) { - retval = true; - break; /* past end of file */ - } - row -= count; - ++lnum; - } - - if (!retval) { - /* Compute the column without wrapping. */ - off = win_col_off(win) - win_col_off2(win); - if (col < off) - col = off; - col += row * (win->w_width - off); - /* add skip column (for long wrapping line) */ - col += win->w_skipcol; - } - - if (!win->w_p_wrap) - col += win->w_leftcol; - - /* skip line number and fold column in front of the line */ - col -= win_col_off(win); - if (col < 0) { - col = 0; - } - - *colp = col; - *rowp = row; - *lnump = lnum; - return retval; -} - -/* - * Find the window at screen position "*rowp" and "*colp". The positions are - * updated to become relative to the top-left of the window. - */ -win_T *mouse_find_win(int *rowp, int *colp) -{ - frame_T *fp; - - fp = topframe; - *rowp -= firstwin->w_winrow; - for (;; ) { - if (fp->fr_layout == FR_LEAF) - break; - if (fp->fr_layout == FR_ROW) { - for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) { - if (*colp < fp->fr_width) - break; - *colp -= fp->fr_width; - } - } else { /* fr_layout == FR_COL */ - for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) { - if (*rowp < fp->fr_height) - break; - *rowp -= fp->fr_height; - } - } - } - return fp->fr_win; -} #if defined(USE_IM_CONTROL) || defined(PROTO) /* diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 2b1543a918..b174af9abe 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -3,27 +3,6 @@ #include <stdbool.h> -/* - * jump_to_mouse() returns one of first four these values, possibly with - * some of the other three added. - */ -#define IN_UNKNOWN 0 -#define IN_BUFFER 1 -#define IN_STATUS_LINE 2 /* on status or command line */ -#define IN_SEP_LINE 4 /* on vertical separator line */ -#define IN_OTHER_WIN 8 /* in other window but can't go there */ -#define CURSOR_MOVED 0x100 -#define MOUSE_FOLD_CLOSE 0x200 /* clicked on '-' in fold column */ -#define MOUSE_FOLD_OPEN 0x400 /* clicked on '+' in fold column */ - -/* flags for jump_to_mouse() */ -#define MOUSE_FOCUS 0x01 /* need to stay in this window */ -#define MOUSE_MAY_VIS 0x02 /* may start Visual mode */ -#define MOUSE_DID_MOVE 0x04 /* only act when mouse has moved */ -#define MOUSE_SETPOS 0x08 /* only set current mouse position */ -#define MOUSE_MAY_STOP_VIS 0x10 /* may stop Visual mode */ -#define MOUSE_RELEASED 0x20 /* button was released */ - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui.h.generated.h" #endif |