mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 07:18:17 +00:00
ui: Remove ui_inchar/ui_char_avail
Also: - Remove NO_CONSOLE_INPUT/NO_CONSULE preprocessor conditionals - Remove ctrl_c_interrupts variable, check for mapped_ctrl_c directly in process_interrupts() - Move ui_inchar profiling to input_poll which is where Nvim blocks for input.
This commit is contained in:
@@ -10273,12 +10273,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 +10367,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;
|
||||
|
@@ -2481,7 +2481,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 +2498,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))
|
||||
|
@@ -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 */
|
||||
|
||||
|
@@ -63,6 +63,7 @@
|
||||
#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,7 +456,7 @@ 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();
|
||||
|
@@ -75,6 +75,7 @@
|
||||
#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 +1643,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;
|
||||
}
|
||||
}
|
||||
|
@@ -2702,11 +2702,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;
|
||||
|
@@ -58,6 +58,7 @@
|
||||
#include "nvim/window.h"
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/shell.h"
|
||||
#include "nvim/os/input.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "misc1.c.generated.h"
|
||||
@@ -2383,7 +2384,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);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#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"
|
||||
|
||||
@@ -184,7 +185,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 +292,7 @@ static void convert_input(void)
|
||||
|
||||
static void process_interrupts(void)
|
||||
{
|
||||
if (!ctrl_c_interrupts) {
|
||||
if (mapped_ctrl_c) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -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,103 +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
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user