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/nvim/ui_client.c | |
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/nvim/ui_client.c')
-rw-r--r-- | src/nvim/ui_client.c | 39 |
1 files changed, 18 insertions, 21 deletions
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; |