diff options
Diffstat (limited to 'src/nvim/ui.c')
-rw-r--r-- | src/nvim/ui.c | 107 |
1 files changed, 76 insertions, 31 deletions
diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 05322a6f64..d3784b6cd3 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -12,10 +12,8 @@ #include "nvim/ex_cmds2.h" #include "nvim/fold.h" #include "nvim/main.h" -#include "nvim/mbyte.h" #include "nvim/ascii.h" #include "nvim/misc1.h" -#include "nvim/misc2.h" #include "nvim/mbyte.h" #include "nvim/garray.h" #include "nvim/memory.h" @@ -27,10 +25,16 @@ #include "nvim/os/time.h" #include "nvim/os/input.h" #include "nvim/os/signal.h" +#include "nvim/popupmnu.h" #include "nvim/screen.h" #include "nvim/syntax.h" #include "nvim/window.h" -#include "nvim/tui/tui.h" +#ifdef FEAT_TUI +# include "nvim/tui/tui.h" +#else +# include "nvim/msgpack_rpc/server.h" +#endif +#include "nvim/api/private/helpers.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui.c.generated.h" @@ -49,29 +53,27 @@ static bool pending_cursor_update = false; static int busy = 0; static int height, width; -// This set of macros allow us to use UI_CALL to invoke any function on -// registered UI instances. The functions can have 0-5 arguments(configurable -// by SELECT_NTH) +// UI_CALL invokes a function on all registered UI instances. The functions can +// have 0-5 arguments (configurable by SELECT_NTH). // -// See http://stackoverflow.com/a/11172679 for a better explanation of how it -// works. +// See http://stackoverflow.com/a/11172679 for how it works. #ifdef _MSC_VER - #define UI_CALL(funname, ...) \ - do { \ - flush_cursor_update(); \ - for (size_t i = 0; i < ui_count; i++) { \ - UI *ui = uis[i]; \ - UI_CALL_MORE(funname, __VA_ARGS__); \ - } \ +# define UI_CALL(funname, ...) \ + do { \ + flush_cursor_update(); \ + for (size_t i = 0; i < ui_count; i++) { \ + UI *ui = uis[i]; \ + UI_CALL_MORE(funname, __VA_ARGS__); \ + } \ } while (0) #else - #define UI_CALL(...) \ - do { \ - flush_cursor_update(); \ - for (size_t i = 0; i < ui_count; i++) { \ - UI *ui = uis[i]; \ - UI_CALL_HELPER(CNT(__VA_ARGS__), __VA_ARGS__); \ - } \ +# define UI_CALL(...) \ + do { \ + flush_cursor_update(); \ + for (size_t i = 0; i < ui_count; i++) { \ + UI *ui = uis[i]; \ + UI_CALL_HELPER(CNT(__VA_ARGS__), __VA_ARGS__); \ + } \ } while (0) #endif #define CNT(...) SELECT_NTH(__VA_ARGS__, MORE, MORE, MORE, MORE, ZERO, ignore) @@ -83,7 +85,21 @@ static int height, width; void ui_builtin_start(void) { +#ifdef FEAT_TUI tui_start(); +#else + fprintf(stderr, "Nvim headless-mode started.\n"); + size_t len; + char **addrs = server_address_list(&len); + if (addrs != NULL) { + fprintf(stderr, "Listening on:\n"); + for (size_t i = 0; i < len; i++) { + fprintf(stderr, "\t%s\n", addrs[i]); + } + xfree(addrs); + } + fprintf(stderr, "Press CTRL+C to exit.\n"); +#endif } void ui_builtin_stop(void) @@ -124,6 +140,15 @@ void ui_set_icon(char *icon) UI_CALL(flush); } +void ui_event(char *name, Array args) +{ + bool args_consumed = false; + UI_CALL(event, name, args, &args_consumed); + if (!args_consumed) { + api_free_array(args); + } +} + // May update the shape of the cursor. void ui_cursor_shape(void) { @@ -137,15 +162,28 @@ void ui_refresh(void) } int width = INT_MAX, height = INT_MAX; + bool pum_external = true; for (size_t i = 0; i < ui_count; i++) { UI *ui = uis[i]; - width = ui->width < width ? ui->width : width; - height = ui->height < height ? ui->height : height; + width = MIN(ui->width, width); + height = MIN(ui->height, height); + pum_external &= ui->pum_external; } row = col = 0; screen_resize(width, height); + pum_set_external(pum_external); +} + +static void ui_refresh_event(void **argv) +{ + ui_refresh(); +} + +void ui_schedule_refresh(void) +{ + loop_schedule(&main_loop, event_create(1, ui_refresh_event, 0)); } void ui_resize(int new_width, int new_height) @@ -188,7 +226,7 @@ void ui_mouse_off(void) UI_CALL(mouse_off); } -void ui_attach(UI *ui) +void ui_attach_impl(UI *ui) { if (ui_count == MAX_UI_COUNT) { abort(); @@ -198,7 +236,7 @@ void ui_attach(UI *ui) ui_refresh(); } -void ui_detach(UI *ui) +void ui_detach_impl(UI *ui) { size_t shift_index = MAX_UI_COUNT; @@ -221,7 +259,7 @@ void ui_detach(UI *ui) } if (--ui_count) { - ui_refresh(); + ui_schedule_refresh(); } } @@ -363,6 +401,9 @@ static void send_output(uint8_t **ptr) UI_CALL(put, NULL, 0); col++; } + if (utf_ambiguous_width(utf_ptr2char(p))) { + pending_cursor_update = true; + } if (col >= width) { ui_linefeed(); } @@ -490,13 +531,17 @@ static void ui_mode_change(void) if (!full_screen) { return; } - /* Get a simple UI mode out of State. */ - if ((State & REPLACE) == REPLACE) + // Get a simple UI mode out of State. + if ((State & REPLACE) == REPLACE) { mode = REPLACE; - else if (State & INSERT) + } else if (State & INSERT) { mode = INSERT; - else + } else if (State & CMDLINE) { + mode = CMDLINE; + } else { mode = NORMAL; + } UI_CALL(mode_change, mode); conceal_check_cursur_line(); } + |