diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-12-30 22:17:01 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-01-05 09:48:26 +0100 |
commit | 47ba78f89a1f0bba8168b4408bc55a3024d5ab97 (patch) | |
tree | 79a1d81956d87986467e4da70b4f9ad53b079040 /src/nvim/ui_client.c | |
parent | ae64772a88125153a438a0e9e43d5f6bcb4eeb28 (diff) | |
download | rneovim-47ba78f89a1f0bba8168b4408bc55a3024d5ab97.tar.gz rneovim-47ba78f89a1f0bba8168b4408bc55a3024d5ab97.tar.bz2 rneovim-47ba78f89a1f0bba8168b4408bc55a3024d5ab97.zip |
refactor(ui): devirtualize the ui layer
- The defined interface for the UI is only the RPC protocol. The original
UI interface as an array of function pointers fill no function.
- On the server, all the UI:s are all RPC channels.
- ui.c is only used on the server.
- The compositor is a preprocessing step for single-grid UI:s
- on the client, ui_client and tui talk directly to each other
- we still do module separation, as ui_client.c could form the basis
of a libnvim client module later.
Items for later PR:s
- vim.ui_attach is still an unhappy child, reconsider based on plugin experience.
- the flags in ui_events.in.h are still a mess. Can be simplified now.
- UX for remote attachment needs more work.
- startup for client can be simplified further (think of the millisecs we can save)
Diffstat (limited to 'src/nvim/ui_client.c')
-rw-r--r-- | src/nvim/ui_client.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 365a76de3f..2821054909 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -15,15 +15,19 @@ #include "nvim/main.h" #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/tui/tui.h" #include "nvim/ui.h" #include "nvim/ui_client.h" +static TUIData *tui = NULL; + // uncrustify:off #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui_client.c.generated.h" # include "ui_events_client.generated.h" #endif // uncrustify:on +// uint64_t ui_client_start_server(int argc, char **argv) { @@ -52,20 +56,20 @@ uint64_t ui_client_start_server(int argc, char **argv) void ui_client_run(bool remote_ui) FUNC_ATTR_NORETURN { - ui_builtin_start(); - - loop_poll_events(&main_loop, 1); + int width, height; + char *term; + tui = tui_start(&width, &height, &term); MAXSIZE_TEMP_ARRAY(args, 3); - ADD_C(args, INTEGER_OBJ(Columns)); - ADD_C(args, INTEGER_OBJ(Rows)); + ADD_C(args, INTEGER_OBJ(width)); + ADD_C(args, INTEGER_OBJ(height)); MAXSIZE_TEMP_DICT(opts, 9); PUT_C(opts, "rgb", BOOLEAN_OBJ(true)); PUT_C(opts, "ext_linegrid", BOOLEAN_OBJ(true)); PUT_C(opts, "ext_termcolors", BOOLEAN_OBJ(true)); - if (ui_client_termname) { - PUT_C(opts, "term_name", STRING_OBJ(cstr_as_string(ui_client_termname))); + if (term) { + PUT(opts, "term_name", STRING_OBJ(cstr_to_string(term))); } if (ui_client_bg_respose != kNone) { bool is_dark = (ui_client_bg_respose == kTrue); @@ -80,6 +84,7 @@ void ui_client_run(bool remote_ui) } } ADD_C(args, DICTIONARY_OBJ(opts)); + rpc_send_event(ui_client_channel_id, "nvim_ui_attach", args); ui_client_attached = true; @@ -89,6 +94,22 @@ void ui_client_run(bool remote_ui) } } +void ui_client_stop(void) +{ + tui_stop(tui); +} + +void ui_client_set_size(int width, int height) +{ + // The currently known size will be sent when attaching + if (ui_client_attached) { + MAXSIZE_TEMP_ARRAY(args, 2); + ADD_C(args, INTEGER_OBJ((int)width)); + ADD_C(args, INTEGER_OBJ((int)height)); + rpc_send_event(ui_client_channel_id, "nvim_ui_try_resize", args); + } +} + UIClientHandler ui_client_get_redraw_handler(const char *name, size_t name_len, Error *error) { int hash = ui_client_handler_hash(name, name_len); @@ -133,7 +154,7 @@ void ui_client_event_grid_resize(Array args) Integer grid = args.items[0].data.integer; Integer width = args.items[1].data.integer; Integer height = args.items[2].data.integer; - ui_call_grid_resize(grid, width, height); + tui_grid_resize(tui, grid, width, height); if (grid_line_buf_size < (size_t)width) { xfree(grid_line_buf_char); @@ -159,6 +180,6 @@ void ui_client_event_raw_line(GridLineEvent *g) // TODO(hlpr98): Accommodate other LineFlags when included in grid_line LineFlags lineflags = 0; - ui_call_raw_line(grid, row, startcol, endcol, clearcol, g->cur_attr, lineflags, - (const schar_T *)grid_line_buf_char, grid_line_buf_attr); + tui_raw_line(tui, grid, row, startcol, endcol, clearcol, g->cur_attr, lineflags, + (const schar_T *)grid_line_buf_char, grid_line_buf_attr); } |