aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/os')
-rw-r--r--src/os/event.c94
-rw-r--r--src/os/event.h2
-rw-r--r--src/os/input.c20
-rw-r--r--src/os/job.c1
4 files changed, 47 insertions, 70 deletions
diff --git a/src/os/event.c b/src/os/event.c
index fb3fffc35a..7fc374e40e 100644
--- a/src/os/event.c
+++ b/src/os/event.c
@@ -20,8 +20,6 @@ KLIST_INIT(Event, Event, _destroy_event)
static klist_t(Event) *event_queue;
static uv_timer_t timer;
static uv_prepare_t timer_prepare;
-static bool poll_uv_loop(int ms);
-static void process_all_events(void);
static void timer_cb(uv_timer_t *handle, int);
static void timer_prepare_cb(uv_prepare_t *, int);
@@ -42,66 +40,8 @@ void event_init()
uv_prepare_init(uv_default_loop(), &timer_prepare);
}
-bool event_poll(int32_t ms)
-{
- int64_t remaining = ms;
- uint64_t end;
- bool result;
-
- if (ms > 0) {
- // Calculate end time in nanoseconds
- end = uv_hrtime() + ms * 1e6;
- }
-
- for (;;) {
- result = poll_uv_loop((int32_t)remaining);
- // Process queued events
- process_all_events();
-
- if (ms > 0) {
- // Calculate remaining time in milliseconds
- remaining = (end - uv_hrtime()) / 1e6;
- }
-
- if (input_ready() || got_int) {
- // Bail out if we have pending input
- return true;
- }
-
- if (!result || (ms >= 0 && remaining <= 0)) {
- // Or if we timed out
- return false;
- }
- }
-}
-
-// Push an event to the queue
-void event_push(Event event)
-{
- *kl_pushp(Event, event_queue) = event;
-}
-
-// Runs the appropriate action for each queued event
-static void process_all_events()
-{
- Event event;
-
- while (kl_shift(Event, event_queue, &event) == 0) {
- switch (event.type) {
- case kEventSignal:
- signal_handle(event);
- break;
- case kEventJobActivity:
- job_handle(event);
- break;
- default:
- abort();
- }
- }
-}
-
// Wait for some event
-static bool poll_uv_loop(int32_t ms)
+bool event_poll(int32_t ms)
{
bool timed_out;
uv_run_mode run_mode = UV_RUN_ONCE;
@@ -145,7 +85,37 @@ static bool poll_uv_loop(int32_t ms)
uv_timer_stop(&timer);
}
- return input_ready() || !kl_empty(event_queue);
+ return input_ready() || event_is_pending();
+}
+
+bool event_is_pending()
+{
+ return !kl_empty(event_queue);
+}
+
+// Push an event to the queue
+void event_push(Event event)
+{
+ *kl_pushp(Event, event_queue) = event;
+}
+
+// Runs the appropriate action for each queued event
+void event_process()
+{
+ Event event;
+
+ while (kl_shift(Event, event_queue, &event) == 0) {
+ switch (event.type) {
+ case kEventSignal:
+ signal_handle(event);
+ break;
+ case kEventJobActivity:
+ job_handle(event);
+ break;
+ default:
+ abort();
+ }
+ }
}
// Set a flag in the `event_poll` loop for signaling of a timeout
diff --git a/src/os/event.h b/src/os/event.h
index 7aee717213..93dc96d55e 100644
--- a/src/os/event.h
+++ b/src/os/event.h
@@ -9,7 +9,9 @@
void event_init(void);
bool event_poll(int32_t ms);
+bool event_is_pending(void);
void event_push(Event event);
+void event_process(void);
#endif // NEOVIM_OS_EVENT_H
diff --git a/src/os/input.c b/src/os/input.c
index 122600630d..ce1dd69fc0 100644
--- a/src/os/input.c
+++ b/src/os/input.c
@@ -145,9 +145,18 @@ int os_inchar(char_u *buf, int maxlen, int32_t ms, int tb_change_cnt)
}
}
+ // If there are pending events, return the keys directly
+ if (maxlen >= 3 && event_is_pending()) {
+ buf[0] = K_SPECIAL;
+ buf[1] = KS_EXTRA;
+ buf[2] = KE_EVENT;
+ return 3;
+ }
+
// If input was put directly in typeahead buffer bail out here.
- if (typebuf_changed(tb_change_cnt))
+ if (typebuf_changed(tb_change_cnt)) {
return 0;
+ }
if (result == kInputEof) {
read_error_exit();
@@ -174,15 +183,12 @@ void os_breakcheck()
// This is a replacement for the old `WaitForChar` function in os_unix.c
static InbufPollResult inbuf_poll(int32_t ms)
{
- if (input_available())
+ if (input_available()) {
return kInputAvail;
+ }
if (event_poll(ms)) {
- if (!got_int && rbuffer.rpos == rbuffer.wpos && eof) {
- return kInputEof;
- }
-
- return kInputAvail;
+ return eof && rbuffer.rpos == rbuffer.wpos ? kInputEof : kInputAvail;
}
return kInputNone;
diff --git a/src/os/job.c b/src/os/job.c
index 8a02de35b7..08e8164015 100644
--- a/src/os/job.c
+++ b/src/os/job.c
@@ -228,7 +228,6 @@ void job_handle(Event event)
job->length,
job->lock == kBufferLockStdout);
- shell_resized();
// restart reading
job->lock = kBufferLockNone;
uv_read_start((uv_stream_t *)&job->proc_stdout, alloc_cb, read_cb);