api/ui: externalize tabline

- Work with a bool[] array parallel to the UIWidget enum.
- Rename some functions.
- Documentation.
This commit is contained in:
Justin M. Keyes
2017-04-25 02:17:15 +02:00
parent 88023d5123
commit 00843902d3
12 changed files with 124 additions and 96 deletions

View File

@@ -47,6 +47,7 @@
#define MAX_UI_COUNT 16
static UI *uis[MAX_UI_COUNT];
static bool ui_ext[UI_WIDGETS] = { 0 };
static size_t ui_count = 0;
static int row = 0, col = 0;
static struct {
@@ -58,10 +59,6 @@ static int busy = 0;
static int height, width;
static int old_mode_idx = -1;
static bool tabline_external = false;
static bool cmdline_external = false;
static bool wildmenu_external = false;
// UI_CALL invokes a function on all registered UI instances. The functions can
// have 0-5 arguments (configurable by SELECT_NTH).
//
@@ -170,21 +167,25 @@ void ui_refresh(void)
}
int width = INT_MAX, height = INT_MAX;
bool pum_external = true;
bool tabline_external = true;
bool ext_widgets[UI_WIDGETS];
for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) {
ext_widgets[i] = true;
}
for (size_t i = 0; i < ui_count; i++) {
UI *ui = uis[i];
width = MIN(ui->width, width);
height = MIN(ui->height, height);
pum_external &= ui->pum_external;
tabline_external &= ui->tabline_external;
for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) {
ext_widgets[i] &= ui->ui_ext[i];
}
}
row = col = 0;
screen_resize(width, height);
pum_set_external(pum_external);
ui_set_widget_external(kUITabline, tabline_external);
for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) {
ui_set_external(i, ext_widgets[i]);
}
ui_mode_info_set();
old_mode_idx = -1;
ui_cursor_shape();
@@ -564,30 +565,16 @@ void ui_cursor_shape(void)
conceal_check_cursur_line();
}
bool ui_is_widget_external(UIWidget widget)
/// Returns true if `widget` is externalized.
bool ui_is_external(UIWidget widget)
{
switch (widget) {
case kUITabline:
return tabline_external;
case kUICmdline:
return cmdline_external;
case kUIWildmenu:
return wildmenu_external;
}
return false;
return ui_ext[widget];
}
void ui_set_widget_external(UIWidget widget, bool external)
/// Sets `widget` as "external".
/// Such widgets are not drawn by Nvim; external UIs are expected to handle
/// higher-level UI events and present the data.
void ui_set_external(UIWidget widget, bool external)
{
switch (widget) {
case kUITabline:
tabline_external = external;
break;
case kUICmdline:
cmdline_external = external;
break;
case kUIWildmenu:
wildmenu_external = external;
break;
}
ui_ext[widget] = external;
}