aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-02-23 18:29:36 +0100
committerJustin M. Keyes <justinkz@gmail.com>2023-02-27 19:50:59 +0100
commit7f424e2b65779c59fc0cac3cc7508ba2ec07f200 (patch)
tree60c2609c51ea9f5708c379972c38d7da32a6faa1
parentf64098a2df774c79dd454f63ac491570cdcaf2b2 (diff)
downloadrneovim-7f424e2b65779c59fc0cac3cc7508ba2ec07f200.tar.gz
rneovim-7f424e2b65779c59fc0cac3cc7508ba2ec07f200.tar.bz2
rneovim-7f424e2b65779c59fc0cac3cc7508ba2ec07f200.zip
feat(api): more fields in nvim_list_uis
Problem: nvim_list_uis does not report all ":help ui-option" fields. Solution: Store ":help ui-option" fields on the `UI` object and update ui_array.
-rw-r--r--runtime/doc/builtin.txt1
-rw-r--r--runtime/doc/news.txt2
-rw-r--r--runtime/doc/ui.txt5
-rw-r--r--src/nvim/api/ui.c16
-rw-r--r--src/nvim/ui.c9
-rw-r--r--src/nvim/ui.h8
-rw-r--r--src/nvim/ui_client.c2
-rw-r--r--test/functional/api/vim_spec.lua18
-rw-r--r--test/functional/terminal/tui_spec.lua37
9 files changed, 72 insertions, 26 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 3ff4e47a45..8cde2f8fb0 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -3868,6 +3868,7 @@ has({feature}) Returns 1 if {feature} is supported, 0 otherwise. The
clipboard |clipboard| provider is available.
fname_case Case in file names matters (for Darwin and MS-Windows
this is not present).
+ gui_running Nvim has a GUI.
iconv Can use |iconv()| for conversion.
linux Linux system.
mac MacOS system.
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index c5261b739d..4c9cbf9189 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -179,6 +179,8 @@ The following new APIs or features were added.
Additionally |TSNode:range()| now takes an optional {include_bytes} argument.
+• |nvim_list_uis()| reports all |ui-option| fields.
+
==============================================================================
CHANGED FEATURES *news-changes*
diff --git a/runtime/doc/ui.txt b/runtime/doc/ui.txt
index bb567e021e..e706e36374 100644
--- a/runtime/doc/ui.txt
+++ b/runtime/doc/ui.txt
@@ -53,9 +53,8 @@ with these (optional) keys:
- `term_name` Sets the name of the terminal 'term'.
- `term_colors` Sets the number of supported colors 't_Co'.
- `term_background` Sets the default value of 'background'.
-- `stdin_fd` Read buffer from `fd` as if it was a stdin pipe.
- This option can only used by |--embed| ui on startup.
- See |ui-startup-stdin|.
+- `stdin_fd` Read buffer 1 from this fd as if it were stdin |--|.
+ Only from |--embed| UI on startup. |ui-startup-stdin|
- `stdin_tty` Tells if `stdin` is a `tty` or not.
- `stdout_tty` Tells if `stdout` is a `tty` or not.
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index f6dee066dc..00fd2781ff 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -113,6 +113,10 @@ void remote_ui_disconnect(uint64_t channel_id)
kv_destroy(data->call_buf);
pmap_del(uint64_t)(&connected_uis, channel_id);
ui_detach_impl(ui, channel_id);
+
+ // Destroy `ui`.
+ XFREE_CLEAR(ui->term_name);
+ XFREE_CLEAR(ui->term_background);
xfree(ui);
}
@@ -163,15 +167,9 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona
UI *ui = xcalloc(1, sizeof(UI));
ui->width = (int)width;
ui->height = (int)height;
- ui->pum_nlines = 0;
- ui->pum_pos = false;
- ui->pum_width = 0.0;
- ui->pum_height = 0.0;
ui->pum_row = -1.0;
ui->pum_col = -1.0;
ui->rgb = true;
- ui->override = false;
-
CLEAR_FIELD(ui->ui_ext);
for (size_t i = 0; i < options.size; i++) {
@@ -320,6 +318,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
set_tty_option("term", string_to_cstr(value.data.string));
+ ui->term_name = string_to_cstr(value.data.string);
return;
}
@@ -328,6 +327,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
t_colors = (int)value.data.integer;
+ ui->term_colors = (int)value.data.integer;
return;
}
@@ -336,6 +336,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
set_tty_background(value.data.string.data);
+ ui->term_background = string_to_cstr(value.data.string);
return;
}
@@ -351,6 +352,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
});
stdin_fd = (int)value.data.integer;
+ ui->stdin_fd = (int)value.data.integer;
return;
}
@@ -359,6 +361,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
stdin_isatty = value.data.boolean;
+ ui->stdin_tty = value.data.boolean;
return;
}
@@ -367,6 +370,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
stdout_isatty = value.data.boolean;
+ ui->stdout_tty = value.data.boolean;
return;
}
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index 73545441d3..6c95579b47 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -598,6 +598,15 @@ Array ui_array(void)
PUT(info, "height", INTEGER_OBJ(ui->height));
PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb));
PUT(info, "override", BOOLEAN_OBJ(ui->override));
+
+ // TUI fields.
+ PUT(info, "term_name", STRING_OBJ(cstr_to_string(ui->term_name)));
+ PUT(info, "term_background", STRING_OBJ(cstr_to_string(ui->term_background)));
+ PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors));
+ PUT(info, "stdin_fd", INTEGER_OBJ(ui->stdin_fd));
+ PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty));
+ PUT(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]));
diff --git a/src/nvim/ui.h b/src/nvim/ui.h
index e83f93eb07..c1377f56b4 100644
--- a/src/nvim/ui.h
+++ b/src/nvim/ui.h
@@ -103,6 +103,14 @@ struct ui_t {
double pum_height;
double pum_width;
+ // TUI fields.
+ char *term_name;
+ char *term_background;
+ int term_colors;
+ int stdin_fd;
+ bool stdin_tty;
+ bool stdout_tty;
+
// TODO(bfredl): integrate into struct!
UIData data[1];
};
diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c
index 8262293ec5..25ff63ea2d 100644
--- a/src/nvim/ui_client.c
+++ b/src/nvim/ui_client.c
@@ -1,6 +1,8 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+/// Nvim's own UI client, which attaches to a child or remote Nvim server.
+
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 3e40967dd5..08abf82f47 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -2549,20 +2549,26 @@ describe('API', function()
{
chan = 1,
ext_cmdline = false,
- ext_popupmenu = false,
- ext_tabline = false,
- ext_wildmenu = false,
+ ext_hlstate = false,
ext_linegrid = screen._options.ext_linegrid or false,
+ ext_messages = false,
ext_multigrid = false,
- ext_hlstate = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
ext_termcolors = false,
- ext_messages = false,
+ ext_wildmenu = false,
height = 4,
- rgb = true,
override = true,
+ rgb = true,
+ stdin_tty = false,
+ stdout_tty = false,
+ term_background = '',
+ term_colors = 0,
+ term_name = '',
width = 20,
}
}
+
eq(expected, nvim("list_uis"))
screen:detach()
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 792ad63e76..9db80e0db2 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -1398,17 +1398,32 @@ describe('TUI', function()
]]}
end)
- it('is included in nvim_list_uis()', function()
- feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(filter(v, {k,v -> k[:3] !=# "ext_" })))})\r')
- screen:expect([=[
- |
- {4:~ }|
- {5: }|
- [[['chan', 1], ['height', 6], ['override', v:false|
- ], ['rgb', v:false], ['width', 50]]] |
- {10:Press ENTER or type command to continue}{1: } |
- {3:-- TERMINAL --} |
- ]=])
+ it('in nvim_list_uis()', function()
+ local expected = {
+ {
+ chan = 1,
+ ext_cmdline = false,
+ ext_hlstate = false,
+ ext_linegrid = true,
+ ext_messages = false,
+ ext_multigrid = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
+ ext_termcolors = true,
+ ext_wildmenu = false,
+ height = 6,
+ override = false,
+ rgb = false,
+ stdin_tty = true,
+ stdout_tty = true,
+ term_background = '',
+ term_colors = 256,
+ term_name = 'xterm-256color', -- $TERM in :terminal.
+ width = 50
+ },
+ }
+ local _, rv = child_session:request('nvim_list_uis')
+ eq(expected, rv)
end)
it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function()