mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
feat(ui): invoke ui client handlers
This commit is contained in:
@@ -112,7 +112,6 @@ static const char *err_too_many_args = N_("Too many edit arguments");
|
|||||||
static const char *err_extra_cmd =
|
static const char *err_extra_cmd =
|
||||||
N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments");
|
N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments");
|
||||||
|
|
||||||
|
|
||||||
void event_init(void)
|
void event_init(void)
|
||||||
{
|
{
|
||||||
loop_init(&main_loop, NULL);
|
loop_init(&main_loop, NULL);
|
||||||
@@ -344,6 +343,12 @@ int main(int argc, char **argv)
|
|||||||
TIME_MSG("init screen for UI");
|
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.
|
init_default_mappings(); // Default mappings.
|
||||||
TIME_MSG("init default mappings");
|
TIME_MSG("init default mappings");
|
||||||
|
|
||||||
@@ -840,9 +845,8 @@ static void remote_request(mparm_T *params, int remote_args,
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_client_init(chan);
|
ui_client_channel_id = chan;
|
||||||
ui_client_execute(chan);
|
return;
|
||||||
abort(); // unreachable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
@@ -547,12 +547,8 @@ void rpc_close(Channel *channel)
|
|||||||
channel->rpc.closed = true;
|
channel->rpc.closed = true;
|
||||||
channel_decref(channel);
|
channel_decref(channel);
|
||||||
|
|
||||||
if (channel->id == ui_client_channel_id) {
|
if (channel->streamtype == kChannelStreamStdio
|
||||||
// TODO(bfredl): handle this in ui_client, where os_exit() is safe
|
|| channel->id == ui_client_channel_id) {
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel->streamtype == kChannelStreamStdio) {
|
|
||||||
multiqueue_put(main_loop.fast_events, exit_event, 0);
|
multiqueue_put(main_loop.fast_events, exit_event, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,21 +26,21 @@ static void add_redraw_event_handler(String method, ApiRedrawWrapper handler)
|
|||||||
void ui_client_init(uint64_t chan)
|
void ui_client_init(uint64_t chan)
|
||||||
{
|
{
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
int width = 80;
|
int width = Columns;
|
||||||
int height = 25;
|
int height = Rows;
|
||||||
Dictionary opts = ARRAY_DICT_INIT;
|
Dictionary opts = ARRAY_DICT_INIT;
|
||||||
|
|
||||||
PUT(opts, "rgb", BOOLEAN_OBJ(true));
|
PUT(opts, "rgb", BOOLEAN_OBJ(true));
|
||||||
PUT(opts, "ext_linegrid", BOOLEAN_OBJ(true));
|
PUT(opts, "ext_linegrid", BOOLEAN_OBJ(true));
|
||||||
PUT(opts, "ext_termcolors", 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)width));
|
||||||
ADD(args, INTEGER_OBJ((int)height));
|
ADD(args, INTEGER_OBJ((int)height));
|
||||||
ADD(args, DICTIONARY_OBJ(opts));
|
ADD(args, DICTIONARY_OBJ(opts));
|
||||||
|
|
||||||
rpc_send_event(chan, "nvim_ui_attach", args);
|
rpc_send_event(chan, "nvim_ui_attach", args);
|
||||||
msgpack_rpc_add_redraw(); // GAME!
|
msgpack_rpc_add_redraw(); // GAME!
|
||||||
|
redraw_methods_table_init();
|
||||||
ui_client_channel_id = chan;
|
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++) {
|
for (size_t i = 0; i < args.size; i++) {
|
||||||
Array call = args.items[i].data.array;
|
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;
|
return NIL;
|
||||||
}
|
}
|
||||||
@@ -80,22 +93,6 @@ void ui_client_execute(uint64_t chan)
|
|||||||
getout(0);
|
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)
|
static HlAttrs redraw_dict2hlattrs(Dictionary redraw_dict, bool rgb)
|
||||||
{
|
{
|
||||||
Error err = ERROR_INIT;
|
Error err = ERROR_INIT;
|
||||||
|
Reference in New Issue
Block a user