mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
Make EventType
enum private to input.c
This enum doesn't need to be public since `event_poll` is only interested in user input(but other events may be handled by libuv callbacks).
This commit is contained in:
@@ -19,15 +19,14 @@ void event_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for some event */
|
/* Wait for some event */
|
||||||
EventType event_poll(int32_t ms)
|
bool event_poll(int32_t ms)
|
||||||
{
|
{
|
||||||
bool timed_out;
|
bool timed_out;
|
||||||
EventType event;
|
|
||||||
uv_run_mode run_mode = UV_RUN_ONCE;
|
uv_run_mode run_mode = UV_RUN_ONCE;
|
||||||
|
|
||||||
if ((event = input_check()) != kEventNone) {
|
if (input_ready()) {
|
||||||
/* If there's a pending input event to be consumed, do it now */
|
/* If there's a pending input event to be consumed, do it now */
|
||||||
return event;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_start();
|
input_start();
|
||||||
@@ -47,11 +46,12 @@ EventType event_poll(int32_t ms)
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* Wait for some event */
|
/* Run one event loop iteration, blocking for events if run_mode is
|
||||||
|
* UV_RUN_ONCE */
|
||||||
uv_run(uv_default_loop(), run_mode);
|
uv_run(uv_default_loop(), run_mode);
|
||||||
} while (
|
} while (
|
||||||
/* Continue running if ... */
|
/* Continue running if ... */
|
||||||
(event = input_check()) == kEventNone && /* ... we have no input */
|
!input_ready() && /* ... we have no input */
|
||||||
run_mode != UV_RUN_NOWAIT && /* ... ms != 0 */
|
run_mode != UV_RUN_NOWAIT && /* ... ms != 0 */
|
||||||
!timed_out /* ... we didn't get a timeout */
|
!timed_out /* ... we didn't get a timeout */
|
||||||
);
|
);
|
||||||
@@ -64,7 +64,7 @@ EventType event_poll(int32_t ms)
|
|||||||
uv_timer_stop(&timer_req);
|
uv_timer_stop(&timer_req);
|
||||||
}
|
}
|
||||||
|
|
||||||
return event;
|
return input_ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a flag in the `event_poll` loop for signaling of a timeout */
|
/* Set a flag in the `event_poll` loop for signaling of a timeout */
|
||||||
|
@@ -2,15 +2,10 @@
|
|||||||
#define NEOVIM_OS_EVENT_H
|
#define NEOVIM_OS_EVENT_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
typedef enum {
|
|
||||||
kEventNone,
|
|
||||||
kEventInput,
|
|
||||||
kEventEof
|
|
||||||
} EventType;
|
|
||||||
|
|
||||||
void event_init(void);
|
void event_init(void);
|
||||||
EventType event_poll(int32_t ms);
|
bool event_poll(int32_t ms);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
#define READ_BUFFER_LENGTH 4096
|
#define READ_BUFFER_LENGTH 4096
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
kInputNone,
|
||||||
|
kInputAvail,
|
||||||
|
kInputEof
|
||||||
|
} InbufPollResult;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uv_buf_t uvbuf;
|
uv_buf_t uvbuf;
|
||||||
uint32_t rpos, wpos, fpos;
|
uint32_t rpos, wpos, fpos;
|
||||||
@@ -31,7 +37,7 @@ static uv_idle_t fread_idle;
|
|||||||
static uv_handle_type read_channel_type;
|
static uv_handle_type read_channel_type;
|
||||||
static bool eof = false;
|
static bool eof = false;
|
||||||
|
|
||||||
static EventType inbuf_poll(int32_t ms);
|
static InbufPollResult inbuf_poll(int32_t ms);
|
||||||
static void stderr_switch(void);
|
static void stderr_switch(void);
|
||||||
static void alloc_cb(uv_handle_t *, size_t, uv_buf_t *);
|
static void alloc_cb(uv_handle_t *, size_t, uv_buf_t *);
|
||||||
static void read_cb(uv_stream_t *, ssize_t, const uv_buf_t *);
|
static void read_cb(uv_stream_t *, ssize_t, const uv_buf_t *);
|
||||||
@@ -53,17 +59,9 @@ void input_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if there's a pending input event */
|
/* Check if there's a pending input event */
|
||||||
EventType input_check()
|
bool input_ready()
|
||||||
{
|
{
|
||||||
if (rbuffer.rpos < rbuffer.wpos) {
|
return rbuffer.rpos < rbuffer.wpos || eof;
|
||||||
return kEventInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eof) {
|
|
||||||
return kEventEof;
|
|
||||||
}
|
|
||||||
|
|
||||||
return kEventNone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Listen for input */
|
/* Listen for input */
|
||||||
@@ -74,7 +72,7 @@ void input_start()
|
|||||||
rbuffer.uvbuf.base = (char *)(rbuffer.data + rbuffer.wpos);
|
rbuffer.uvbuf.base = (char *)(rbuffer.data + rbuffer.wpos);
|
||||||
|
|
||||||
if (read_channel_type == UV_FILE) {
|
if (read_channel_type == UV_FILE) {
|
||||||
/* Just invoke the `fread_idle_cb` as soon as there are no pending events */
|
/* Just invoke the `fread_idle_cb` as soon as the loop starts */
|
||||||
uv_idle_start(&fread_idle, fread_idle_cb);
|
uv_idle_start(&fread_idle, fread_idle_cb);
|
||||||
} else {
|
} else {
|
||||||
/* Start reading */
|
/* Start reading */
|
||||||
@@ -126,14 +124,14 @@ uint32_t input_read(char *buf, uint32_t count)
|
|||||||
/* Low level input function. */
|
/* Low level input function. */
|
||||||
int mch_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt)
|
int mch_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt)
|
||||||
{
|
{
|
||||||
EventType result;
|
InbufPollResult result;
|
||||||
|
|
||||||
if (ms >= 0) {
|
if (ms >= 0) {
|
||||||
if ((result = inbuf_poll(ms)) != kEventInput) {
|
if ((result = inbuf_poll(ms)) != kInputAvail) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((result = inbuf_poll(p_ut)) != kEventInput) {
|
if ((result = inbuf_poll(p_ut)) != kInputAvail) {
|
||||||
if (trigger_cursorhold() && maxlen >= 3 &&
|
if (trigger_cursorhold() && maxlen >= 3 &&
|
||||||
!typebuf_changed(tb_change_cnt)) {
|
!typebuf_changed(tb_change_cnt)) {
|
||||||
buf[0] = K_SPECIAL;
|
buf[0] = K_SPECIAL;
|
||||||
@@ -151,7 +149,7 @@ int mch_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt)
|
|||||||
if (typebuf_changed(tb_change_cnt))
|
if (typebuf_changed(tb_change_cnt))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (result == kEventEof) {
|
if (result == kInputEof) {
|
||||||
read_error_exit();
|
read_error_exit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -162,7 +160,7 @@ int mch_inchar(char_u *buf, int maxlen, long ms, int tb_change_cnt)
|
|||||||
/* Check if a character is available for reading */
|
/* Check if a character is available for reading */
|
||||||
bool mch_char_avail()
|
bool mch_char_avail()
|
||||||
{
|
{
|
||||||
return inbuf_poll(0) == kEventInput;
|
return inbuf_poll(0) == kInputAvail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -171,17 +169,24 @@ bool mch_char_avail()
|
|||||||
*/
|
*/
|
||||||
void mch_breakcheck()
|
void mch_breakcheck()
|
||||||
{
|
{
|
||||||
if (curr_tmode == TMODE_RAW && event_poll(0) == kEventInput)
|
if (curr_tmode == TMODE_RAW && event_poll(0))
|
||||||
fill_input_buf(FALSE);
|
fill_input_buf(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is a replacement for the old `WaitForChar` function in os_unix.c */
|
/* This is a replacement for the old `WaitForChar` function in os_unix.c */
|
||||||
static EventType inbuf_poll(int32_t ms)
|
static InbufPollResult inbuf_poll(int32_t ms)
|
||||||
{
|
{
|
||||||
if (input_available())
|
if (input_available())
|
||||||
return kEventInput;
|
return kInputAvail;
|
||||||
|
|
||||||
return event_poll(ms);
|
if (event_poll(ms)) {
|
||||||
|
if (rbuffer.rpos == rbuffer.wpos && eof) {
|
||||||
|
return kInputEof;
|
||||||
|
}
|
||||||
|
return kInputAvail;
|
||||||
|
}
|
||||||
|
|
||||||
|
return kInputNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stderr_switch()
|
static void stderr_switch()
|
||||||
|
@@ -4,11 +4,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "os/event.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void input_init(void);
|
void input_init(void);
|
||||||
EventType input_check(void);
|
bool input_ready(void);
|
||||||
void input_start(void);
|
void input_start(void);
|
||||||
void input_stop(void);
|
void input_stop(void);
|
||||||
uint32_t input_read(char *buf, uint32_t count);
|
uint32_t input_read(char *buf, uint32_t count);
|
||||||
|
Reference in New Issue
Block a user