aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/input.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-12-06 11:27:36 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-12-08 23:44:23 -0300
commit07e569a25dba4bf6d9743102a34666964efb45cb (patch)
treef0a1e6bc8546327365cae045505a6d059a87d64f /src/nvim/os/input.c
parent8b6cfff6a18d839d11900cd1fade5938dc9a02d5 (diff)
downloadrneovim-07e569a25dba4bf6d9743102a34666964efb45cb.tar.gz
rneovim-07e569a25dba4bf6d9743102a34666964efb45cb.tar.bz2
rneovim-07e569a25dba4bf6d9743102a34666964efb45cb.zip
ui: Add abstract_ui termcap and split UI layer
This is how Nvim behaves when the "abstract_ui" termcap is activated: - No data is written/read to stdout/stdin by default. - Instead of sending data to stdout, ui_write will parse the termcap codes and invoke dispatch functions in the ui.c module. - The dispatch functions will forward the calls to all attached UI instances(each UI instance is an implementation of the UI layer and is registered with ui_attach). - Like with the "builtin_gui" termcap, "abstract_ui" does not contain any key sequences. Instead, vim key strings(<cr>, <esc>, etc) are parsed directly by input_enqueue and the translated strings are pushed to the input buffer. With this new input model, its not possible to send mouse events yet. Thats because mouse sequence parsing happens in term.c/check_termcodes which must return early when "abstract_ui" is activated.
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r--src/nvim/os/input.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index 686fe1f06d..246ebf123c 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -46,7 +46,7 @@ void input_init(void)
{
input_buffer = rbuffer_new(INPUT_BUFFER_SIZE + MAX_KEY_CODE_LEN);
- if (embedded_mode) {
+ if (abstract_ui) {
return;
}
@@ -57,7 +57,7 @@ void input_init(void)
void input_teardown(void)
{
- if (embedded_mode) {
+ if (abstract_ui) {
return;
}
@@ -67,7 +67,7 @@ void input_teardown(void)
// Listen for input
void input_start(void)
{
- if (embedded_mode) {
+ if (abstract_ui) {
return;
}
@@ -77,7 +77,7 @@ void input_start(void)
// Stop listening for input
void input_stop(void)
{
- if (embedded_mode) {
+ if (abstract_ui) {
return;
}
@@ -180,7 +180,23 @@ void input_buffer_restore(String str)
size_t input_enqueue(String keys)
{
- size_t rv = rbuffer_write(input_buffer, keys.data, keys.size);
+ char *ptr = keys.data, *end = ptr + keys.size;
+
+ while (rbuffer_available(input_buffer) >= 6 && ptr < end) {
+ int new_size = trans_special((char_u **)&ptr,
+ (char_u *)rbuffer_write_ptr(input_buffer),
+ false);
+ if (!new_size) {
+ // copy the character unmodified
+ *rbuffer_write_ptr(input_buffer) = *ptr++;
+ new_size = 1;
+ }
+ // TODO(tarruda): Don't produce past unclosed '<' characters, except if
+ // there's a lot of characters after the '<'
+ rbuffer_produced(input_buffer, (size_t)new_size);
+ }
+
+ size_t rv = (size_t)(ptr - keys.data);
process_interrupts();
return rv;
}
@@ -255,7 +271,7 @@ static void read_cb(RStream *rstream, void *data, bool at_eof)
static void convert_input(void)
{
- if (embedded_mode || !rbuffer_available(input_buffer)) {
+ if (abstract_ui || !rbuffer_available(input_buffer)) {
// No input buffer space
return;
}
@@ -335,7 +351,7 @@ static bool input_ready(void)
return typebuf_was_filled || // API call filled typeahead
rbuffer_pending(input_buffer) > 0 || // Stdin input
event_has_deferred() || // Events must be processed
- (!embedded_mode && eof); // Stdin closed
+ (!abstract_ui && eof); // Stdin closed
}
// Exit because of an input read error.