diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-12-31 14:23:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-31 14:23:24 +0100 |
commit | cce736218f465511194465410e1ba23b5530e46f (patch) | |
tree | 02f488ea361a4fba8aec92e44193d8627836cd55 /src/nvim/ui.c | |
parent | 99cf111289bfcd14981255e805da43bac5139141 (diff) | |
parent | 9fdcbbb4063daa125e420e0ffe9dae6801c264bc (diff) | |
download | rneovim-cce736218f465511194465410e1ba23b5530e46f.tar.gz rneovim-cce736218f465511194465410e1ba23b5530e46f.tar.bz2 rneovim-cce736218f465511194465410e1ba23b5530e46f.zip |
Merge pull request #18375 from bfredl/tui_rework
feat(ui): refactor TUI from thread to separate process
Diffstat (limited to 'src/nvim/ui.c')
-rw-r--r-- | src/nvim/ui.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 7bde8d2f5a..33c7d0c1fe 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -10,6 +10,7 @@ #include "auto/config.h" #include "klib/kvec.h" +#include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" #include "nvim/buffer_defs.h" @@ -31,16 +32,11 @@ #include "nvim/option.h" #include "nvim/os/time.h" #include "nvim/strings.h" +#include "nvim/tui/tui.h" #include "nvim/ui.h" #include "nvim/ui_compositor.h" #include "nvim/vim.h" #include "nvim/window.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" @@ -126,28 +122,28 @@ void ui_init(void) kv_ensure_space(call_buf, 16); } +static UI *builtin_ui = NULL; + +#ifdef EXITFREE void ui_free_all_mem(void) { kv_destroy(call_buf); + if (builtin_ui) { + tui_free_all_mem(builtin_ui); + builtin_ui = NULL; + } } +#endif 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 + builtin_ui = tui_start(); +} + +UI *ui_get_by_index(int idx) +{ + assert(idx < 16); + return uis[idx]; } bool ui_rgb_attached(void) @@ -186,7 +182,7 @@ void ui_refresh(void) } if (updating_screen) { - deferred_refresh_event(NULL); + ui_schedule_refresh(); return; } @@ -228,10 +224,20 @@ void ui_refresh(void) screen_resize(width, height); p_lz = save_p_lz; } else { - Array args = ARRAY_DICT_INIT; - ADD(args, INTEGER_OBJ((int)width)); - ADD(args, INTEGER_OBJ((int)height)); - rpc_send_event(ui_client_channel_id, "nvim_ui_try_resize", args); + if (ui_client_attached) { + // TODO(bfredl): ui_refresh() should only be used on the server + // we are in the client process. forward the resize + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ((int)width)); + ADD(args, INTEGER_OBJ((int)height)); + rpc_send_event(ui_client_channel_id, "nvim_ui_try_resize", args); + } else { + /// TODO(bfredl): Messy! The screen does not yet exist, but we need to + /// communicate its size from the TUI to the client. Clean this up + /// in The UI Devirtualization Project. + Rows = height; + Columns = width; + } } if (ext_widgets[kUIMessages]) { @@ -279,10 +285,6 @@ static void ui_refresh_event(void **argv) void ui_schedule_refresh(void) { - loop_schedule_fast(&main_loop, event_create(deferred_refresh_event, 0)); -} -static void deferred_refresh_event(void **argv) -{ multiqueue_put(resize_events, ui_refresh_event, 0); } |