diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-20 10:39:54 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-21 11:05:49 -0300 |
commit | b527ac752fd5ebcc74c06306e7009e2b98e4ee01 (patch) | |
tree | 0785b3f76cb371967ad0b28446611d1a1af60a96 /src/nvim/os/input.c | |
parent | 264e0d872c598062be2b2a118d38c89a6ed5a023 (diff) | |
download | rneovim-b527ac752fd5ebcc74c06306e7009e2b98e4ee01.tar.gz rneovim-b527ac752fd5ebcc74c06306e7009e2b98e4ee01.tar.bz2 rneovim-b527ac752fd5ebcc74c06306e7009e2b98e4ee01.zip |
event: Extract event_poll loops to `event_poll_until` macro
A pattern that is becoming common across the project is to poll for events until
a certain condition is true, optionally passing a timeout. To address this
scenario, the event_poll_until macro was created and the job/channel/input
modules were refactored to use it on their blocking functions.
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r-- | src/nvim/os/input.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index d718bf95da..d9dae2b44e 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -163,13 +163,10 @@ void input_buffer_restore(String str) free(str.data); } -static bool input_poll(int32_t ms) +static bool input_poll(int ms) { - if (embedded_mode) { - return event_poll(ms); - } - - return input_ready() || event_poll(ms) || input_ready(); + event_poll_until(ms, input_ready()); + return input_ready(); } // This is a replacement for the old `WaitForChar` function in os_unix.c @@ -294,6 +291,10 @@ static int push_event_key(uint8_t *buf, int maxlen) // Check if there's pending input static bool input_ready(void) { - return rstream_pending(read_stream) > 0 || eof; + 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 } |