aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/event.c20
-rw-r--r--src/nvim/os/input.c60
2 files changed, 59 insertions, 21 deletions
diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c
index 1477072f4f..34560610bd 100644
--- a/src/nvim/os/event.c
+++ b/src/nvim/os/event.c
@@ -18,6 +18,8 @@
#include "nvim/vim.h"
#include "nvim/memory.h"
#include "nvim/misc2.h"
+#include "nvim/term.h"
+#include "nvim/screen.h"
#include "nvim/lib/klist.h"
@@ -39,6 +41,7 @@ typedef struct {
// loop(to avoid recursion), but before returning from
// `event_poll`
static klist_t(Event) *deferred_events = NULL, *immediate_events = NULL;
+static int deferred_events_allowed = 0;
void event_init(void)
{
@@ -134,7 +137,17 @@ void event_poll(int ms)
bool event_has_deferred(void)
{
- return !kl_empty(deferred_events);
+ return deferred_events_allowed && !kl_empty(deferred_events);
+}
+
+void event_enable_deferred(void)
+{
+ ++deferred_events_allowed;
+}
+
+void event_disable_deferred(void)
+{
+ --deferred_events_allowed;
}
// Queue an event
@@ -146,6 +159,11 @@ void event_push(Event event, bool deferred)
void event_process(void)
{
process_events_from(deferred_events);
+
+ if (must_redraw) {
+ update_screen(0);
+ out_flush();
+ }
}
static void process_events_from(klist_t(Event) *queue)
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index 3ebfb3f12b..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)
@@ -84,13 +87,11 @@ void input_stop(void)
// Low level input function.
int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
{
- InbufPollResult result;
-
- if (event_has_deferred()) {
- // Return pending event bytes
- return push_event_key(buf, maxlen);
+ if (rbuffer_pending(input_buffer)) {
+ return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
}
+ InbufPollResult result;
if (ms >= 0) {
if ((result = inbuf_poll(ms)) == kInputNone) {
return 0;
@@ -110,24 +111,27 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
}
}
- // If there are deferred events, return the keys directly
- if (event_has_deferred()) {
- return push_event_key(buf, maxlen);
- }
-
// If input was put directly in typeahead buffer bail out here.
if (typebuf_changed(tb_change_cnt)) {
return 0;
}
+ if (rbuffer_pending(input_buffer)) {
+ // 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);
+ }
+
+ // If there are deferred events, return the keys directly
+ if (event_has_deferred()) {
+ return push_event_key(buf, maxlen);
+ }
+
if (result == kInputEof) {
read_error_exit();
- return 0;
}
- // 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);
+ return 0;
}
// Check if a character is available for reading
@@ -183,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();
}
@@ -281,7 +294,7 @@ static void convert_input(void)
static void process_interrupts(void)
{
- if (!ctrl_c_interrupts) {
+ if (mapped_ctrl_c) {
return;
}
@@ -319,10 +332,17 @@ 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
- (!embedded_mode && (
- rbuffer_pending(input_buffer) > 0 || // Stdin input
- eof)); // Stdin closed
+ return typebuf_was_filled || // API call filled typeahead
+ rbuffer_pending(input_buffer) > 0 || // Stdin input
+ event_has_deferred() || // Events must be processed
+ (!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();
+}