diff options
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r-- | src/nvim/os/input.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index e4501aeb82..d948a48b64 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -20,8 +20,8 @@ #include "nvim/getchar.h" #include "nvim/term.h" -#define READ_BUFFER_SIZE 0xffff -#define INPUT_BUFFER_SIZE 4096 +#define READ_BUFFER_SIZE 0xfff +#define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4) typedef enum { kInputNone, @@ -116,7 +116,6 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt) return 0; } - convert_input(); // Safe to convert rbuffer_read to int, it will never overflow since // we use relatively small buffers. return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen); @@ -132,8 +131,8 @@ bool os_char_avail(void) // In cooked mode we should get SIGINT, no need to check. void os_breakcheck(void) { - if (curr_tmode == TMODE_RAW && input_poll(0)) - convert_input(); + if (curr_tmode == TMODE_RAW) + input_poll(0); } /// Test whether a file descriptor refers to a terminal. @@ -166,6 +165,13 @@ void input_buffer_restore(String str) free(str.data); } +size_t input_enqueue(String keys) +{ + size_t rv = rbuffer_write(input_buffer, keys.data, keys.size); + process_interrupts(); + return rv; +} + static bool input_poll(int ms) { event_poll_until(ms, input_ready()); @@ -220,6 +226,8 @@ static void read_cb(RStream *rstream, void *data, bool at_eof) } } + convert_input(); + process_interrupts(); started_reading = true; } @@ -260,7 +268,10 @@ static void convert_input(void) // data points to memory allocated by `string_convert_ext`, free it. free(data); } +} +static void process_interrupts(void) +{ if (!ctrl_c_interrupts) { return; } @@ -299,10 +310,10 @@ static int push_event_key(uint8_t *buf, int maxlen) // Check if there's pending input static bool input_ready(void) { - return typebuf_was_filled || // API call filled typeahead - event_has_deferred() || // Events must be processed + return typebuf_was_filled || // API call filled typeahead + event_has_deferred() || // Events must be processed (!embedded_mode && ( - rstream_pending(read_stream) > 0 || // Stdin input - eof)); // Stdin closed + rbuffer_pending(input_buffer) > 0 || // Stdin input + eof)); // Stdin closed } |