refactor(api): use arena for nvim_list_uis()

This commit is contained in:
bfredl 2024-02-09 12:40:48 +01:00
parent e0e5b7f0ba
commit e9510211f0
3 changed files with 20 additions and 26 deletions

View File

@ -247,10 +247,9 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona
void ui_attach(uint64_t channel_id, Integer width, Integer height, Boolean enable_rgb, Error *err)
FUNC_API_DEPRECATED_SINCE(1)
{
Dictionary opts = ARRAY_DICT_INIT;
PUT(opts, "rgb", BOOLEAN_OBJ(enable_rgb));
MAXSIZE_TEMP_DICT(opts, 1);
PUT_C(opts, "rgb", BOOLEAN_OBJ(enable_rgb));
nvim_ui_attach(channel_id, width, height, opts, err);
api_free_dictionary(opts);
}
/// Tells the nvim server if focus was gained or lost by the GUI
@ -1113,9 +1112,3 @@ void remote_ui_event(UI *ui, char *name, Array args)
free_ret:
arena_mem_free(arena_finish(&arena));
}
void remote_ui_inspect(UI *ui, Dictionary *info)
{
UIData *data = ui->data;
PUT(*info, "chan", INTEGER_OBJ((Integer)data->channel_id));
}

View File

@ -1866,10 +1866,10 @@ Dictionary nvim__stats(Arena *arena)
/// - "rgb" true if the UI uses RGB colors (false implies |cterm-colors|)
/// - "ext_..." Requested UI extensions, see |ui-option|
/// - "chan" |channel-id| of remote UI
Array nvim_list_uis(void)
Array nvim_list_uis(Arena *arena)
FUNC_API_SINCE(4)
{
return ui_array();
return ui_array(arena);
}
/// Gets the immediate children of process `pid`.

View File

@ -645,34 +645,35 @@ bool ui_has(UIExtension ext)
return ui_ext[ext];
}
Array ui_array(void)
Array ui_array(Arena *arena)
{
Array all_uis = ARRAY_DICT_INIT;
Array all_uis = arena_array(arena, ui_count);
for (size_t i = 0; i < ui_count; i++) {
UI *ui = uis[i];
Dictionary info = ARRAY_DICT_INIT;
PUT(info, "width", INTEGER_OBJ(ui->width));
PUT(info, "height", INTEGER_OBJ(ui->height));
PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb));
PUT(info, "override", BOOLEAN_OBJ(ui->override));
Dictionary info = arena_dict(arena, 10 + kUIExtCount);
PUT_C(info, "width", INTEGER_OBJ(ui->width));
PUT_C(info, "height", INTEGER_OBJ(ui->height));
PUT_C(info, "rgb", BOOLEAN_OBJ(ui->rgb));
PUT_C(info, "override", BOOLEAN_OBJ(ui->override));
// TUI fields. (`stdin_fd` is intentionally omitted.)
PUT(info, "term_name", CSTR_TO_OBJ(ui->term_name));
PUT_C(info, "term_name", CSTR_AS_OBJ(ui->term_name));
// term_background is deprecated. Populate with an empty string
PUT(info, "term_background", CSTR_TO_OBJ(""));
PUT_C(info, "term_background", STATIC_CSTR_AS_OBJ(""));
PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors));
PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty));
PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty));
PUT_C(info, "term_colors", INTEGER_OBJ(ui->term_colors));
PUT_C(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty));
PUT_C(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty));
for (UIExtension j = 0; j < kUIExtCount; j++) {
if (ui_ext_names[j][0] != '_' || ui->ui_ext[j]) {
PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j]));
PUT_C(info, (char *)ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j]));
}
}
remote_ui_inspect(ui, &info);
ADD(all_uis, DICTIONARY_OBJ(info));
PUT_C(info, "chan", INTEGER_OBJ((Integer)ui->data->channel_id));
ADD_C(all_uis, DICTIONARY_OBJ(info));
}
return all_uis;
}