mirror of
https://github.com/neovim/neovim.git
synced 2025-09-26 21:18:34 +00:00
Merge #8456 'API: nvim_list_uis: include channel id'
This commit is contained in:
@@ -97,6 +97,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
|
||||
ui->set_icon = remote_ui_set_icon;
|
||||
ui->option_set = remote_ui_option_set;
|
||||
ui->event = remote_ui_event;
|
||||
ui->inspect = remote_ui_inspect;
|
||||
|
||||
memset(ui->ui_ext, 0, sizeof(ui->ui_ext));
|
||||
|
||||
@@ -275,3 +276,9 @@ static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
|
||||
}
|
||||
push_call(ui, name, my_args);
|
||||
}
|
||||
|
||||
static void remote_ui_inspect(UI *ui, Dictionary *info)
|
||||
{
|
||||
UIData *data = ui->data;
|
||||
PUT(*info, "chan", INTEGER_OBJ((Integer)data->channel_id));
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ void set_title(String title)
|
||||
void set_icon(String icon)
|
||||
FUNC_API_SINCE(3);
|
||||
void option_set(String name, Object value)
|
||||
FUNC_API_SINCE(4);
|
||||
FUNC_API_SINCE(4) FUNC_API_BRIDGE_IMPL;
|
||||
|
||||
void popupmenu_show(Array items, Integer selected, Integer row, Integer col)
|
||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||
|
@@ -1747,6 +1747,14 @@ Dictionary nvim__stats(void)
|
||||
/// Gets a list of dictionaries representing attached UIs.
|
||||
///
|
||||
/// @return Array of UI dictionaries
|
||||
///
|
||||
/// Each dictionary has the following keys:
|
||||
/// - "height" requested height of the UI
|
||||
/// - "width" requested width of the UI
|
||||
/// - "rgb" whether the UI uses rgb colors (false implies cterm colors)
|
||||
/// - "ext_..." Requested UI extensions, see |ui-options|
|
||||
/// - "chan" Channel id of remote UI (not present for TUI)
|
||||
///
|
||||
Array nvim_list_uis(void)
|
||||
FUNC_API_SINCE(4)
|
||||
{
|
||||
|
@@ -535,14 +535,18 @@ Array ui_array(void)
|
||||
{
|
||||
Array all_uis = ARRAY_DICT_INIT;
|
||||
for (size_t i = 0; i < ui_count; i++) {
|
||||
Dictionary dic = ARRAY_DICT_INIT;
|
||||
PUT(dic, "width", INTEGER_OBJ(uis[i]->width));
|
||||
PUT(dic, "height", INTEGER_OBJ(uis[i]->height));
|
||||
PUT(dic, "rgb", BOOLEAN_OBJ(uis[i]->rgb));
|
||||
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));
|
||||
for (UIExtension j = 0; j < kUIExtCount; j++) {
|
||||
PUT(dic, ui_ext_names[j], BOOLEAN_OBJ(uis[i]->ui_ext[j]));
|
||||
PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j]));
|
||||
}
|
||||
ADD(all_uis, DICTIONARY_OBJ(dic));
|
||||
if (ui->inspect) {
|
||||
ui->inspect(ui, &info);
|
||||
}
|
||||
ADD(all_uis, DICTIONARY_OBJ(info));
|
||||
}
|
||||
return all_uis;
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ struct ui_t {
|
||||
#endif
|
||||
void (*event)(UI *ui, char *name, Array args, bool *args_consumed);
|
||||
void (*stop)(UI *ui);
|
||||
void (*inspect)(UI *ui, Dictionary *info);
|
||||
};
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
|
@@ -163,3 +163,28 @@ static void ui_bridge_suspend_event(void **argv)
|
||||
UI *ui = UI(argv[0]);
|
||||
ui->suspend(ui);
|
||||
}
|
||||
|
||||
static void ui_bridge_option_set(UI *ui, String name, Object value)
|
||||
{
|
||||
String copy_name = copy_string(name);
|
||||
Object *copy_value = xmalloc(sizeof(Object));
|
||||
*copy_value = copy_object(value);
|
||||
UI_BRIDGE_CALL(ui, option_set, 4, ui, copy_name.data,
|
||||
INT2PTR(copy_name.size), copy_value);
|
||||
// TODO(bfredl): when/if TUI/bridge teardown is refactored to use events, the
|
||||
// commit that introduced this special case can be reverted.
|
||||
// For now this is needed for nvim_list_uis().
|
||||
if (strequal(name.data, "termguicolors")) {
|
||||
ui->rgb = value.data.boolean;
|
||||
}
|
||||
}
|
||||
static void ui_bridge_option_set_event(void **argv)
|
||||
{
|
||||
UI *ui = UI(argv[0]);
|
||||
String name = (String){ .data = argv[1], .size = (size_t)argv[2] };
|
||||
Object value = *(Object *)argv[3];
|
||||
ui->option_set(ui, name, value);
|
||||
api_free_string(name);
|
||||
api_free_object(value);
|
||||
xfree(argv[3]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user