Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9ad12e

Browse filesBrowse files
committed
UI/nvim_ui_attach(): add override option
Before now, Nvim always degrades UI capabilities to the lowest-common denominator. For example, if any connected UI has `ext_messages=false` then `ext_messages=true` requested by any other connected UI is ignored. Now `nvim_ui_attach()` supports `override=true`, which flips the behavior: if any UI requests an `ext_*` UI capability then the capability is enabled (and the legacy behavior is disabled). Legacy UIs will be broken while a `override=true` UI is connected, but it's useful for debugging: you can type into the TUI and observe the UI events from another connected (UI) client. And the legacy UI will "recover" after the `override=true` UI disconnects. Example using pynvim: >>> n.ui_attach(2048, 2048, rgb=True, override=True, ext_multigrid=True, ext_messages=True, ext_popupmenu=True) >>> while True: n.next_message();
1 parent 8330cc2 commit b9ad12e
Copy full SHA for b9ad12e

File tree

Expand file treeCollapse file tree

9 files changed

+64
-32
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+64
-32
lines changed

‎runtime/doc/debug.txt

Copy file name to clipboardExpand all lines: runtime/doc/debug.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ line numbers. Double-click one of the lines and the Find Source dialog will
108108
appear. Navigate to the directory where the Vim source is (if you have it.)
109109

110110
If you don't know how to debug this any further, follow the instructions
111-
at ":help bug-reports". Paste the call stack into the bug report.
111+
at ":help bug-report". Paste the call stack into the bug report.
112112

113113
If you have a non-free version of Visual Studio, you can save a minidump via
114114
the Debug menu and send it with the bug report. A minidump is a small file

‎runtime/doc/deprecated.txt

Copy file name to clipboardExpand all lines: runtime/doc/deprecated.txt
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ Options ~
6868
*'viminfofile'* Deprecated alias to 'shadafile' option.
6969

7070
UI extensions~
71-
*ui-wildmenu* Use `ext_cmdline` and `ext_popupmenu` instead.
72-
Enabled by `ext_wildmenu` |ui-options|.
73-
If `ext_wildmenu` is set, these events are emitted for
74-
backwards-compatibility:
71+
*ui-wildmenu* Use |ui-cmdline| with |ui-popupmenu| instead. Enabled
72+
by `ext_wildmenu` |ui-options|. Emits these events:
7573
["wildmenu_show", items]
7674
["wildmenu_select", selected]
7775
["wildmenu_hide"]

‎runtime/doc/intro.txt

Copy file name to clipboardExpand all lines: runtime/doc/intro.txt
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ For more information try one of these:
5858
==============================================================================
5959
Nvim on the interwebs *internet*
6060

61-
*www* *WWW* *faq* *FAQ* *distribution* *download*
61+
*www* *faq* *distribution* *download*
6262

6363
Nvim home page: https://neovim.io/
6464
Nvim FAQ: https://github.com/neovim/neovim/wiki/FAQ
@@ -67,9 +67,10 @@ Nvim on the interwebs *internet*
6767
Vim home page: https://www.vim.org/
6868

6969

70-
Bug reports: *bugs* *bug-reports* *bugreport.vim*
70+
*bugs* *bug-report* *bugreport.vim* *feature-request*
7171

72-
Report bugs on GitHub: https://github.com/neovim/neovim/issues
72+
Report bugs and request features here:
73+
https://github.com/neovim/neovim/issues
7374

7475
Be brief, yet complete. Always give a reproducible example and try to find
7576
out which settings or other things trigger the bug.

‎runtime/doc/ui.txt

Copy file name to clipboardExpand all lines: runtime/doc/ui.txt
+23-17Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ done by an embedder, see |ui-startup| below for details, but an UI can also
2525
connect to a running nvim instance and invoke this method. `options` must be
2626
a dictionary with these (optional) keys:
2727
`rgb` Decides the color format. *ui-rgb*
28-
Set true (default) for 24-bit RGB colors.
29-
Set false for terminal colors (max of 256).
28+
true: (default) 24-bit RGB colors
29+
false: Terminal colors (8-bit, max 256)
30+
`override` Decides how UI capabilities are resolved.
31+
true: Enable requested UI capabilities, even
32+
if not supported by all connected UIs
33+
(including |TUI|).
34+
false: (default) Disable UI capabilities not
35+
supported by all connected UIs
36+
(including TUI).
3037
*ui-ext-options*
31-
`ext_popupmenu` Externalize the popupmenu. |ui-popupmenu|
38+
`ext_popupmenu` Externalize |popupmenu-completion| and
39+
'wildmenu'. |ui-popupmenu|
3240
`ext_tabline` Externalize the tabline. |ui-tabline|
3341
`ext_cmdline` Externalize the cmdline. |ui-cmdline|
34-
`ext_wildmenu` Externalize the wildmenu (deprecated). |ui-wildmenu|
3542
`ext_messages` Externalize messages. |ui-messages|
3643
`ext_linegrid` Use new revision of the grid events. |ui-linegrid|
3744
`ext_multigrid` Use per-window grid based events. |ui-multigrid|
@@ -245,9 +252,9 @@ numerical highlight ids to the actual attributes.
245252
implementation, where using the terminal builtin ("ANSI") defaults
246253
are expected.
247254

248-
Note: unlike the corresponding events in the first revision, the
249-
screen is not always cleared after sending this event. The GUI has to
250-
repaint the screen with changed background color itself.
255+
Note: Unlike the corresponding |ui-grid-old| events, the screen is not
256+
always cleared after sending this event. The UI must repaint the
257+
screen with changed background color itself.
251258

252259
*ui-event-hl_attr_define*
253260
["hl_attr_define", id, rgb_attr, cterm_attr, info]
@@ -554,6 +561,7 @@ See |nvim_input_mouse| for sending mouse events to Nvim.
554561
Popupmenu Events *ui-popupmenu*
555562

556563
Only sent if `ext_popupmenu` option is set in |ui-options|.
564+
Events for |popupmenu-completion| and command-line 'wildmenu'.
557565

558566
["popupmenu_show", items, selected, row, col, grid]
559567
Show |popupmenu-completion|. `items` is an array of completion items
@@ -590,9 +598,7 @@ Only sent if `ext_tabline` option is set in |ui-options|
590598
Cmdline Events *ui-cmdline*
591599

592600
Only sent if `ext_cmdline` option is set in |ui-options|. To handle
593-
command-line completion (wildmenu), use |ui-popupmenu| events activated by
594-
|ext_popupmenu| option. (The `ext_wildmenu` option only exists for backwards
595-
compatibility).
601+
command-line 'wildmenu', enable |ui-popupmenu| and handle its events.
596602

597603
["cmdline_show", content, pos, firstc, prompt, indent, level]
598604
content: List of [attrs, string]
@@ -650,18 +656,18 @@ compatibility).
650656
==============================================================================
651657
Message Events *ui-messages*
652658

653-
Only sent if `ext_messages` option is set in |ui-options|. This option implies
654-
`ext_linegrid` and `ext_cmdline` also being set. |ui-linegrid| and |ui-cmdline| events
655-
will thus also be sent.
659+
Only sent if `ext_messages` option is set in |ui-options|. This option
660+
implicitly enables `ext_linegrid` and `ext_cmdline`. |ui-linegrid| and
661+
|ui-cmdline| events will thus also be sent.
656662

657663
This extension allows the UI to control the display of messages that otherwise
658664
would have been displayed in the message/cmdline area in the bottom of the
659665
screen.
660666

661-
Activating this extension means that Nvim will allocate no screen space for
662-
the cmdline or messages, and 'cmdheight' will be set to zero. Attempting to
663-
change 'cmdheight' will silently be ignored. |ui-cmdline| events will be used
664-
to represent the state of the cmdline.
667+
Activating this extension means that Nvim will not allocate screen space for
668+
the cmdline or messages, 'cmdheight' will be zero. Attempting to change
669+
'cmdheight' will be silently ignored. |ui-cmdline| events represent the state
670+
of the cmdline.
665671

666672
["msg_show", kind, content, replace_last]
667673
Display a message to the user.

‎src/nvim/api/ui.c

Copy file name to clipboardExpand all lines: src/nvim/api/ui.c
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
110110
ui->width = (int)width;
111111
ui->height = (int)height;
112112
ui->rgb = true;
113+
ui->override = false;
113114
ui->grid_resize = remote_ui_grid_resize;
114115
ui->grid_clear = remote_ui_grid_clear;
115116
ui->grid_cursor_goto = remote_ui_grid_cursor_goto;
@@ -236,6 +237,15 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
236237
static void ui_set_option(UI *ui, bool init, String name, Object value,
237238
Error *error)
238239
{
240+
if (strequal(name.data, "override")) {
241+
if (value.type != kObjectTypeBoolean) {
242+
api_set_error(error, kErrorTypeValidation, "override must be a Boolean");
243+
return;
244+
}
245+
ui->override = value.data.boolean;
246+
return;
247+
}
248+
239249
if (strequal(name.data, "rgb")) {
240250
if (value.type != kObjectTypeBoolean) {
241251
api_set_error(error, kErrorTypeValidation, "rgb must be a Boolean");

‎src/nvim/ui.c

Copy file name to clipboardExpand all lines: src/nvim/ui.c
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ bool ui_rgb_attached(void)
141141
return false;
142142
}
143143

144+
/// Returns true if any UI requested `override=true`.
145+
bool ui_override(void)
146+
{
147+
for (size_t i = 1; i < ui_count; i++) {
148+
if (uis[i]->override) {
149+
return true;
150+
}
151+
}
152+
return false;
153+
}
154+
144155
bool ui_active(void)
145156
{
146157
return ui_count > 1;
@@ -173,12 +184,13 @@ void ui_refresh(void)
173184
ext_widgets[i] = true;
174185
}
175186

187+
bool inclusive = ui_override();
176188
for (size_t i = 0; i < ui_count; i++) {
177189
UI *ui = uis[i];
178190
width = MIN(ui->width, width);
179191
height = MIN(ui->height, height);
180192
for (UIExtension j = 0; (int)j < kUIExtCount; j++) {
181-
ext_widgets[j] &= ui->ui_ext[j];
193+
ext_widgets[j] &= (ui->ui_ext[j] || inclusive);
182194
}
183195
}
184196

@@ -431,6 +443,7 @@ Array ui_array(void)
431443
PUT(info, "width", INTEGER_OBJ(ui->width));
432444
PUT(info, "height", INTEGER_OBJ(ui->height));
433445
PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb));
446+
PUT(info, "override", BOOLEAN_OBJ(ui->override));
434447
for (UIExtension j = 0; j < kUIExtCount; j++) {
435448
if (ui_ext_names[j][0] != '_' || ui->ui_ext[j]) {
436449
PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j]));

‎src/nvim/ui.h

Copy file name to clipboardExpand all lines: src/nvim/ui.h
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ typedef int LineFlags;
4848

4949
struct ui_t {
5050
bool rgb;
51+
bool override; ///< Force highest-requested UI capabilities.
5152
bool composed;
52-
bool ui_ext[kUIExtCount]; ///< Externalized widgets
53-
int width, height;
53+
bool ui_ext[kUIExtCount]; ///< Externalized UI capabilities.
54+
int width;
55+
int height;
5456
void *data;
5557

5658
#ifdef INCLUDE_GENERATED_DECLARATIONS

‎test/functional/api/vim_spec.lua

Copy file name to clipboardExpand all lines: test/functional/api/vim_spec.lua
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ describe('API', function()
12841284
end)
12851285
it('returns attached UIs', function()
12861286
local screen = Screen.new(20, 4)
1287-
screen:attach()
1287+
screen:attach({override=true})
12881288
local expected = {
12891289
{
12901290
chan = 1,
@@ -1299,6 +1299,7 @@ describe('API', function()
12991299
ext_messages = false,
13001300
height = 4,
13011301
rgb = true,
1302+
override = true,
13021303
width = 20,
13031304
}
13041305
}
@@ -1308,6 +1309,7 @@ describe('API', function()
13081309
screen = Screen.new(44, 99)
13091310
screen:attach({ rgb = false })
13101311
expected[1].rgb = false
1312+
expected[1].override = false
13111313
expected[1].width = 44
13121314
expected[1].height = 99
13131315
eq(expected, nvim("list_uis"))

‎test/functional/terminal/tui_spec.lua

Copy file name to clipboardExpand all lines: test/functional/terminal/tui_spec.lua
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ describe('TUI', function()
255255
]])
256256
end)
257257

258-
it('shows up in nvim_list_uis', function()
258+
it('is included in nvim_list_uis()', function()
259259
feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(filter(v, {k,v -> k[:3] !=# "ext_" })))})\013')
260260
screen:expect([=[
261261
|
262262
{4:~ }|
263263
{5: }|
264-
[[['height', 6], ['rgb', v:false], ['width', 50]]]|
265-
|
264+
[[['height', 6], ['override', v:false], ['rgb', v:|
265+
false], ['width', 50]]] |
266266
{10:Press ENTER or type command to continue}{1: } |
267267
{3:-- TERMINAL --} |
268268
]=])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.