aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgeekodour <hrishikeshbman@gmail.com>2018-02-16 14:10:40 +0530
committerJustin M. Keyes <justinkz@gmail.com>2018-03-03 15:06:24 +0100
commit9f994bb69925ed943b17d03f2cad7d5e2c21e992 (patch)
treec5ee2bc3413b1bcd60db99700fc40cf88587f2ed
parent37b755ab47a20418fca45c81037a973b4cc027e6 (diff)
downloadrneovim-9f994bb69925ed943b17d03f2cad7d5e2c21e992.tar.gz
rneovim-9f994bb69925ed943b17d03f2cad7d5e2c21e992.tar.bz2
rneovim-9f994bb69925ed943b17d03f2cad7d5e2c21e992.zip
api: nvim_list_uis #8004
ref #7438 closes #4842
-rw-r--r--src/nvim/api/vim.c10
-rw-r--r--src/nvim/ui.c16
-rw-r--r--test/functional/api/vim_spec.lua41
3 files changed, 66 insertions, 1 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 0e7cc428d4..dad67c5e4b 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -35,6 +35,7 @@
#include "nvim/os/input.h"
#include "nvim/viml/parser/expressions.h"
#include "nvim/viml/parser/parser.h"
+#include "nvim/ui.h"
#define LINE_BUFFER_SIZE 4096
@@ -1468,3 +1469,12 @@ Float nvim__id_float(Float flt)
{
return flt;
}
+
+/// Gets a list of dictionaries representing attached UIs.
+///
+/// @return Array of UI dictionaries
+Array nvim_list_uis(void)
+ FUNC_API_SINCE(4)
+{
+ return ui_array();
+}
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index f4d3cd987d..c70a02d960 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -526,3 +526,19 @@ bool ui_is_external(UIExtension widget)
{
return ui_ext[widget];
}
+
+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));
+ for (UIExtension j = 0; j < kUIExtCount; j++) {
+ PUT(dic, ui_ext_names[j], BOOLEAN_OBJ(uis[i]->ui_ext[j]));
+ }
+ ADD(all_uis, DICTIONARY_OBJ(dic));
+ }
+ return all_uis;
+}
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 1faed4e9b1..bd56161a54 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -745,7 +745,7 @@ describe('api', function()
end)
end)
- describe('list_runtime_paths', function()
+ describe('nvim_list_runtime_paths', function()
it('returns nothing with empty &runtimepath', function()
meths.set_option('runtimepath', '')
eq({}, meths.list_runtime_paths())
@@ -998,4 +998,43 @@ describe('api', function()
it, _check_parsing, hl, fmtn)
end)
+ describe('nvim_list_uis', function()
+ it('returns empty if --headless', function()
+ -- --embed implies --headless.
+ eq({}, nvim("list_uis"))
+ end)
+ it('returns attached UIs', function()
+ local screen = Screen.new(20, 4)
+ screen:attach()
+ local expected = {
+ {
+ ext_cmdline = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
+ ext_wildmenu = false,
+ height = 4,
+ rgb = true,
+ width = 20,
+ }
+ }
+ eq(expected, nvim("list_uis"))
+
+ screen:detach()
+ screen = Screen.new(44, 99)
+ screen:attach({ rgb = false })
+ expected = {
+ {
+ ext_cmdline = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
+ ext_wildmenu = false,
+ height = 99,
+ rgb = false,
+ width = 44,
+ }
+ }
+ eq(expected, nvim("list_uis"))
+ end)
+ end)
+
end)