diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-03-12 23:17:32 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-03-15 19:55:34 +0100 |
commit | 534edce3c4972d1c8da44fbcf60e7946c09a5612 (patch) | |
tree | deacf7c1af76b41101f31efab5ddd19796b1d97e /src | |
parent | 794d2744f33562326172801ddd729853e7135347 (diff) | |
download | rneovim-534edce3c4972d1c8da44fbcf60e7946c09a5612.tar.gz rneovim-534edce3c4972d1c8da44fbcf60e7946c09a5612.tar.bz2 rneovim-534edce3c4972d1c8da44fbcf60e7946c09a5612.zip |
feat(ui): invoke ui client handlers
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/main.c | 12 | ||||
-rw-r--r-- | src/nvim/msgpack_rpc/channel.c | 8 | ||||
-rw-r--r-- | src/nvim/ui_client.c | 39 |
3 files changed, 28 insertions, 31 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 95ef306745..d67b47e82c 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -112,7 +112,6 @@ static const char *err_too_many_args = N_("Too many edit arguments"); static const char *err_extra_cmd = N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments"); - void event_init(void) { loop_init(&main_loop, NULL); @@ -344,6 +343,12 @@ int main(int argc, char **argv) TIME_MSG("init screen for UI"); } + if (ui_client_channel_id) { + ui_client_init(ui_client_channel_id); + ui_client_execute(ui_client_channel_id); + abort(); // unreachable + } + init_default_mappings(); // Default mappings. TIME_MSG("init default mappings"); @@ -840,9 +845,8 @@ static void remote_request(mparm_T *params, int remote_args, exit(1); } - ui_client_init(chan); - ui_client_execute(chan); - abort(); // unreachable + ui_client_channel_id = chan; + return; } Array args = ARRAY_DICT_INIT; diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index f4e836fa81..48ecd5d0ea 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -547,12 +547,8 @@ void rpc_close(Channel *channel) channel->rpc.closed = true; channel_decref(channel); - if (channel->id == ui_client_channel_id) { - // TODO(bfredl): handle this in ui_client, where os_exit() is safe - exit(0); - } - - if (channel->streamtype == kChannelStreamStdio) { + if (channel->streamtype == kChannelStreamStdio + || channel->id == ui_client_channel_id) { multiqueue_put(main_loop.fast_events, exit_event, 0); } } diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index b23ceefb6f..c13bfc2d07 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -26,21 +26,21 @@ static void add_redraw_event_handler(String method, ApiRedrawWrapper handler) void ui_client_init(uint64_t chan) { Array args = ARRAY_DICT_INIT; - int width = 80; - int height = 25; + int width = Columns; + int height = Rows; Dictionary opts = ARRAY_DICT_INIT; PUT(opts, "rgb", BOOLEAN_OBJ(true)); PUT(opts, "ext_linegrid", BOOLEAN_OBJ(true)); PUT(opts, "ext_termcolors", BOOLEAN_OBJ(true)); - // TODO(bfredl): use the size of the client UI ADD(args, INTEGER_OBJ((int)width)); ADD(args, INTEGER_OBJ((int)height)); ADD(args, DICTIONARY_OBJ(opts)); rpc_send_event(chan, "nvim_ui_attach", args); msgpack_rpc_add_redraw(); // GAME! + redraw_methods_table_init(); ui_client_channel_id = chan; } @@ -61,9 +61,22 @@ Object ui_client_handle_redraw(uint64_t channel_id, Array args, Error *error) { for (size_t i = 0; i < args.size; i++) { Array call = args.items[i].data.array; - char *method_name = call.items[0].data.string.data; + String name = call.items[0].data.string; + + ApiRedrawWrapper handler = map_get(String, ApiRedrawWrapper)(&redraw_methods, name); + if (!handler) { + ELOG("No redraw handler by name: %s", name.size ? name.data : "<empty>"); + continue; + } + + // fprintf(stderr, "%s: %zu\n", name.data, call.size-1); + + DLOG("Invoke redraw handler by name: %s", name.data); + for (size_t j = 1; j < call.size; j++) { + Array internal_call_args = call.items[j].data.array; + handler(internal_call_args); + } - fprintf(stderr, "%s: %zu\n", method_name, call.size-1); } return NIL; } @@ -80,22 +93,6 @@ void ui_client_execute(uint64_t chan) getout(0); } -/// @param name Redraw method name -/// @param name_len name size (includes terminating NUL) -ApiRedrawWrapper get_redraw_event_handler(const char *name, size_t name_len, Error *error) -{ - String m = { .data = (char *)name, .size = name_len }; - ApiRedrawWrapper rv = - map_get(String, ApiRedrawWrapper)(&redraw_methods, m); - - if (!rv) { - api_set_error(error, kErrorTypeException, "Invalid method: %.*s", - m.size > 0 ? (int)m.size : (int)sizeof("<empty>"), - m.size > 0 ? m.data : "<empty>"); - } - return rv; -} - static HlAttrs redraw_dict2hlattrs(Dictionary redraw_dict, bool rgb) { Error err = ERROR_INIT; |