diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-03-25 22:08:14 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-03-25 22:08:14 -0300 |
commit | a6e53a3797a93fe060f807fe2e4c6361854b6c97 (patch) | |
tree | b684785ba9c769491e6ebdac8e21495cf22dbdd3 /src/nvim/os | |
parent | d2d99454e63c0e6649fddd52bbd9a10d27c2e347 (diff) | |
parent | 2aa2513b8e023a0d7bd2071299f0ea59a4d4ce25 (diff) | |
download | rneovim-a6e53a3797a93fe060f807fe2e4c6361854b6c97.tar.gz rneovim-a6e53a3797a93fe060f807fe2e4c6361854b6c97.tar.bz2 rneovim-a6e53a3797a93fe060f807fe2e4c6361854b6c97.zip |
Merge PR #2076 'Builtin terminal emulation'
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/event.c | 18 | ||||
-rw-r--r-- | src/nvim/os/job.c | 13 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c index c4d38c6a28..fd9ff5b230 100644 --- a/src/nvim/os/event.c +++ b/src/nvim/os/event.c @@ -20,6 +20,7 @@ #include "nvim/misc2.h" #include "nvim/ui.h" #include "nvim/screen.h" +#include "nvim/terminal.h" #include "nvim/lib/klist.h" @@ -63,6 +64,7 @@ void event_init(void) // finish mspgack-rpc initialization channel_init(); server_init(); + terminal_init(); } void event_teardown(void) @@ -74,11 +76,16 @@ void event_teardown(void) process_events_from(immediate_events); process_events_from(deferred_events); + // reset the stop_flag to ensure `uv_run` below won't exit early. This hack + // is required because the `process_events_from` above may call `event_push` + // which will set the stop_flag to 1(uv_stop) + uv_default_loop()->stop_flag = 0; input_stop_stdin(); channel_teardown(); job_teardown(); server_teardown(); signal_teardown(); + terminal_teardown(); // this last `uv_run` will return after all handles are stopped, it will // also take care of finishing any uv_close calls made by other *_teardown // functions. @@ -153,17 +160,18 @@ void event_disable_deferred(void) // Queue an event void event_push(Event event, bool deferred) { + // Sometimes libuv will run pending callbacks(timer for example) before + // blocking for a poll. If this happens and the callback pushes a event to one + // of the queues, the event would only be processed after the poll + // returns(user hits a key for example). To avoid this scenario, we call + // uv_stop when a event is enqueued. + uv_stop(uv_default_loop()); *kl_pushp(Event, deferred ? deferred_events : immediate_events) = event; } void event_process(void) { process_events_from(deferred_events); - - if (must_redraw) { - update_screen(0); - ui_flush(); - } } static void process_events_from(klist_t(Event) *queue) diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index 898d875ea3..ccd7891601 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -406,6 +406,12 @@ static void close_cb(uv_handle_t *handle) job_decref(handle_get_job(handle)); } +static void job_exited(Event event) +{ + Job *job = event.data; + process_close(job); +} + static void chld_handler(uv_signal_t *handle, int signum) { int stat = 0; @@ -433,7 +439,12 @@ static void chld_handler(uv_signal_t *handle, int signum) } else if (WIFSIGNALED(stat)) { job->status = WTERMSIG(stat); } - process_close(job); + if (exiting) { + // don't enqueue more events when exiting + process_close(job); + } else { + event_push((Event) {.handler = job_exited, .data = job}, false); + } break; } } |