aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-06-03 08:29:45 +0200
committerGitHub <noreply@github.com>2018-06-03 08:29:45 +0200
commit402a797d08a5d943d28be1b795bb4d80f17887c7 (patch)
tree47c2dc6e202a690274e43eda8bf4f01e7c0d4dd1
parent39a03c0fe736629cf7804dbaf9b73df60aa237cd (diff)
parentb8331e1a1cc99129495e655bce171f583661edda (diff)
downloadrneovim-402a797d08a5d943d28be1b795bb4d80f17887c7.tar.gz
rneovim-402a797d08a5d943d28be1b795bb4d80f17887c7.tar.bz2
rneovim-402a797d08a5d943d28be1b795bb4d80f17887c7.zip
Merge #8456 'API: nvim_list_uis: include channel id'
-rw-r--r--src/nvim/api/ui.c7
-rw-r--r--src/nvim/api/ui_events.in.h2
-rw-r--r--src/nvim/api/vim.c8
-rw-r--r--src/nvim/ui.c16
-rw-r--r--src/nvim/ui.h1
-rw-r--r--src/nvim/ui_bridge.c25
-rw-r--r--test/functional/api/vim_spec.lua2
-rw-r--r--test/functional/terminal/tui_spec.lua13
8 files changed, 67 insertions, 7 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 4cd2657561..b6e0b9a566 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -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));
+}
diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h
index 96d494460b..3ef16a7ac3 100644
--- a/src/nvim/api/ui_events.in.h
+++ b/src/nvim/api/ui_events.in.h
@@ -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;
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index f587948cf0..b73ecc2d03 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -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)
{
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index 42366fdb76..21dd6ec0dd 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -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]));
+ }
+ if (ui->inspect) {
+ ui->inspect(ui, &info);
}
- ADD(all_uis, DICTIONARY_OBJ(dic));
+ ADD(all_uis, DICTIONARY_OBJ(info));
}
return all_uis;
}
diff --git a/src/nvim/ui.h b/src/nvim/ui.h
index 48896a6a3f..6b04e9c67a 100644
--- a/src/nvim/ui.h
+++ b/src/nvim/ui.h
@@ -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
diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c
index a8bbeea035..56db124a46 100644
--- a/src/nvim/ui_bridge.c
+++ b/src/nvim/ui_bridge.c
@@ -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]);
+}
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 1e910b6aa7..3a686c84e7 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -1226,6 +1226,7 @@ describe('api', function()
screen:attach()
local expected = {
{
+ chan = 1,
ext_cmdline = false,
ext_popupmenu = false,
ext_tabline = false,
@@ -1242,6 +1243,7 @@ describe('api', function()
screen:attach({ rgb = false })
expected = {
{
+ chan = 1,
ext_cmdline = false,
ext_popupmenu = false,
ext_tabline = false,
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 0ae5802a01..5603224975 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -253,6 +253,19 @@ describe('tui', function()
{4:-- TERMINAL --} |
]])
end)
+
+ it('shows up in nvim_list_uis', function()
+ feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(v))})\013')
+ screen:expect([=[
+ {5: }|
+ [[['ext_cmdline', v:false], ['ext_popupmenu', v:fa|
+ lse], ['ext_tabline', v:false], ['ext_wildmenu', v|
+ :false], ['height', 6], ['rgb', v:false], ['width'|
+ , 50]]] |
+ {10:Press ENTER or type command to continue}{1: } |
+ {3:-- TERMINAL --} |
+ ]=])
+ end)
end)
describe('tui with non-tty file descriptors', function()