aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2018-02-13 13:45:49 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2018-02-13 20:48:51 +0100
commit6e5cb0debd23693175bd05409d3f1af4015567df (patch)
treeda2298632595dc2d42c921a323ebd63978c27b82 /src
parent0f1bc5ddceb50ca8f96d91aabf8157d9758af0cd (diff)
downloadrneovim-6e5cb0debd23693175bd05409d3f1af4015567df.tar.gz
rneovim-6e5cb0debd23693175bd05409d3f1af4015567df.tar.bz2
rneovim-6e5cb0debd23693175bd05409d3f1af4015567df.zip
ui: refactor ui options
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/private/helpers.c7
-rw-r--r--src/nvim/api/ui.c30
-rw-r--r--src/nvim/ui.c24
-rw-r--r--src/nvim/ui.h14
-rw-r--r--src/nvim/ui_bridge.c2
5 files changed, 41 insertions, 36 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 9baa996560..65c306d4b1 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -26,6 +26,7 @@
#include "nvim/version.h"
#include "nvim/lib/kvec.h"
#include "nvim/getchar.h"
+#include "nvim/ui.h"
/// Helper structure for vim_to_object
typedef struct {
@@ -955,6 +956,12 @@ static void init_ui_event_metadata(Dictionary *metadata)
msgpack_rpc_to_object(&unpacked.data, &ui_events);
msgpack_unpacked_destroy(&unpacked);
PUT(*metadata, "ui_events", ui_events);
+ Array ui_options = ARRAY_DICT_INIT;
+ ADD(ui_options, STRING_OBJ(cstr_to_string("rgb")));
+ for (UIExtension i = 0; i < kUIExtCount; i++) {
+ ADD(ui_options, STRING_OBJ(cstr_to_string(ui_ext_names[i])));
+ }
+ PUT(*metadata, "ui_options", ARRAY_OBJ(ui_options));
}
static void init_error_type_metadata(Dictionary *metadata)
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index e53a45bd93..4870c3fb8a 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -176,18 +176,6 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
static void ui_set_option(UI *ui, String name, Object value, Error *error)
{
-#define UI_EXT_OPTION(o, e) \
- do { \
- if (strequal(name.data, #o)) { \
- if (value.type != kObjectTypeBoolean) { \
- api_set_error(error, kErrorTypeValidation, #o " must be a Boolean"); \
- return; \
- } \
- ui->ui_ext[(e)] = value.data.boolean; \
- return; \
- } \
- } while (0)
-
if (strequal(name.data, "rgb")) {
if (value.type != kObjectTypeBoolean) {
api_set_error(error, kErrorTypeValidation, "rgb must be a Boolean");
@@ -197,13 +185,21 @@ static void ui_set_option(UI *ui, String name, Object value, Error *error)
return;
}
- UI_EXT_OPTION(ext_cmdline, kUICmdline);
- UI_EXT_OPTION(ext_popupmenu, kUIPopupmenu);
- UI_EXT_OPTION(ext_tabline, kUITabline);
- UI_EXT_OPTION(ext_wildmenu, kUIWildmenu);
+ for (UIExtension i = 0; i < kUIExtCount; i++) {
+ if (strequal(name.data, ui_ext_names[i])) {
+ if (value.type != kObjectTypeBoolean) {
+ snprintf((char *)IObuff, IOSIZE, "%s must be a Boolean",
+ ui_ext_names[i]);
+ api_set_error(error, kErrorTypeValidation, (char *)IObuff);
+ return;
+ }
+ ui->ui_ext[i] = value.data.boolean;
+ return;
+ }
+ }
if (strequal(name.data, "popupmenu_external")) {
- // LEGACY: Deprecated option, use `ui_ext` instead.
+ // LEGACY: Deprecated option, use `ext_cmdline` instead.
if (value.type != kObjectTypeBoolean) {
api_set_error(error, kErrorTypeValidation,
"popupmenu_external must be a Boolean");
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index e8f5477db0..3f4f17824b 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -49,7 +49,7 @@
#define MAX_UI_COUNT 16
static UI *uis[MAX_UI_COUNT];
-static bool ui_ext[UI_WIDGETS] = { 0 };
+static bool ui_ext[kUIExtCount] = { 0 };
static size_t ui_count = 0;
static int row = 0, col = 0;
static struct {
@@ -246,8 +246,8 @@ void ui_refresh(void)
}
int width = INT_MAX, height = INT_MAX;
- bool ext_widgets[UI_WIDGETS];
- for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) {
+ bool ext_widgets[kUIExtCount];
+ for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
ext_widgets[i] = true;
}
@@ -255,7 +255,7 @@ void ui_refresh(void)
UI *ui = uis[i];
width = MIN(ui->width, width);
height = MIN(ui->height, height);
- for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) {
+ for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
ext_widgets[i] &= ui->ui_ext[i];
}
}
@@ -267,8 +267,10 @@ void ui_refresh(void)
screen_resize(width, height);
p_lz = save_p_lz;
- for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) {
- ui_set_external(i, ext_widgets[i]);
+ for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
+ ui_ext[i] = ext_widgets[i];
+ ui_call_option_set(cstr_as_string((char *)ui_ext_names[i]),
+ BOOLEAN_OBJ(ext_widgets[i]));
}
ui_mode_info_set();
old_mode_idx = -1;
@@ -527,15 +529,7 @@ void ui_cursor_shape(void)
}
/// Returns true if `widget` is externalized.
-bool ui_is_external(UIWidget widget)
+bool ui_is_external(UIExtension widget)
{
return ui_ext[widget];
}
-
-/// 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)
-{
- ui_ext[widget] = external;
-}
diff --git a/src/nvim/ui.h b/src/nvim/ui.h
index 60adcb974f..48896a6a3f 100644
--- a/src/nvim/ui.h
+++ b/src/nvim/ui.h
@@ -13,14 +13,22 @@ typedef enum {
kUIPopupmenu,
kUITabline,
kUIWildmenu,
-} UIWidget;
-#define UI_WIDGETS (kUIWildmenu + 1)
+ kUIExtCount,
+} UIExtension;
+
+EXTERN const char *ui_ext_names[] INIT(= {
+ "ext_cmdline",
+ "ext_popupmenu",
+ "ext_tabline",
+ "ext_wildmenu"
+});
+
typedef struct ui_t UI;
struct ui_t {
bool rgb;
- bool ui_ext[UI_WIDGETS]; ///< Externalized widgets
+ bool ui_ext[kUIExtCount]; ///< Externalized widgets
int width, height;
void *data;
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c
index b0f8905771..c936a17e52 100644
--- a/src/nvim/ui_bridge.c
+++ b/src/nvim/ui_bridge.c
@@ -67,7 +67,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
rv->bridge.option_set = ui_bridge_option_set;
rv->scheduler = scheduler;
- for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) {
+ for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
rv->bridge.ui_ext[i] = ui->ui_ext[i];
}