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();
This commit is contained in:
Justin M. Keyes
2019-05-09 19:35:38 +02:00
parent 8330cc22af
commit b9ad12e6c2
9 changed files with 64 additions and 32 deletions

View File

@@ -141,6 +141,17 @@ bool ui_rgb_attached(void)
return false;
}
/// Returns true if any UI requested `override=true`.
bool ui_override(void)
{
for (size_t i = 1; i < ui_count; i++) {
if (uis[i]->override) {
return true;
}
}
return false;
}
bool ui_active(void)
{
return ui_count > 1;
@@ -173,12 +184,13 @@ void ui_refresh(void)
ext_widgets[i] = true;
}
bool inclusive = ui_override();
for (size_t i = 0; i < ui_count; i++) {
UI *ui = uis[i];
width = MIN(ui->width, width);
height = MIN(ui->height, height);
for (UIExtension j = 0; (int)j < kUIExtCount; j++) {
ext_widgets[j] &= ui->ui_ext[j];
ext_widgets[j] &= (ui->ui_ext[j] || inclusive);
}
}
@@ -431,6 +443,7 @@ Array ui_array(void)
PUT(info, "width", INTEGER_OBJ(ui->width));
PUT(info, "height", INTEGER_OBJ(ui->height));
PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb));
PUT(info, "override", BOOLEAN_OBJ(ui->override));
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]));