aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/input.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-06-20 10:36:58 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-06-24 13:02:23 -0300
commitef4c5ccb21bda85cea7fa3c825f865c95f6cdbb4 (patch)
treefeb546e72f9afdcc3f9d6138b7173e223fecbcc7 /src/nvim/os/input.c
parentb00a37544c2d0662e251fd80033509cb6ed8ffe2 (diff)
downloadrneovim-ef4c5ccb21bda85cea7fa3c825f865c95f6cdbb4.tar.gz
rneovim-ef4c5ccb21bda85cea7fa3c825f865c95f6cdbb4.tar.bz2
rneovim-ef4c5ccb21bda85cea7fa3c825f865c95f6cdbb4.zip
event: Decouple user input checks from `event_poll`
This was done to generalize the usage of `event_poll`, which will now return `true` only if a event has been processed/deferred before the timeout(if not -1). To do that, the `input_ready` calls have been extracted to the input.c module(the `event_poll` call has been surrounded by `input_ready` calls, resulting in the same behavior). The `input_start`/`input_stop` calls still present in `event_poll` are temporary: When the API becomes the only way to read user input, it will no longer be necessary to start/stop the input stream.
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r--src/nvim/os/input.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index 6e42cba4ad..0f6d2df12f 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -37,12 +37,6 @@ void input_init()
rstream_set_file(read_stream, read_cmd_fd);
}
-// Check if there's pending input
-bool input_ready()
-{
- return rstream_available(read_stream) > 0 || eof;
-}
-
// Listen for input
void input_start()
{
@@ -119,7 +113,7 @@ bool os_char_avail()
// In cooked mode we should get SIGINT, no need to check.
void os_breakcheck()
{
- if (curr_tmode == TMODE_RAW && event_poll(0))
+ if (curr_tmode == TMODE_RAW && input_poll(0))
fill_input_buf(false);
}
@@ -132,6 +126,11 @@ bool os_isatty(int fd)
return uv_guess_handle(fd) == UV_TTY;
}
+static bool input_poll(int32_t ms)
+{
+ return input_ready() || event_poll(ms) || input_ready();
+}
+
// This is a replacement for the old `WaitForChar` function in os_unix.c
static InbufPollResult inbuf_poll(int32_t ms)
{
@@ -139,7 +138,7 @@ static InbufPollResult inbuf_poll(int32_t ms)
return kInputAvail;
}
- if (event_poll(ms)) {
+ if (input_poll(ms)) {
return eof && rstream_available(read_stream) == 0 ?
kInputEof :
kInputAvail;
@@ -196,3 +195,10 @@ static int push_event_key(uint8_t *buf, int maxlen)
return buf_idx;
}
+
+// Check if there's pending input
+bool input_ready()
+{
+ return rstream_available(read_stream) > 0 || eof;
+}
+