diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2016-06-16 16:14:10 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2016-08-29 10:17:31 +0200 |
commit | e968d72cae57180921ad9cf24cde74fedc8b03d3 (patch) | |
tree | 88df0a694355501d6f18cc96e586c2f00dca074b /src | |
parent | 999af47be82ca822d6a70e9e0ba8fe29549fa4a8 (diff) | |
download | rneovim-e968d72cae57180921ad9cf24cde74fedc8b03d3.tar.gz rneovim-e968d72cae57180921ad9cf24cde74fedc8b03d3.tar.bz2 rneovim-e968d72cae57180921ad9cf24cde74fedc8b03d3.zip |
api/ui: use ui options instead of one method per feature
Use new nvim_ui_ prefix to avoid breaking change.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/ui.c | 92 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 1 | ||||
-rw-r--r-- | src/nvim/ui.c | 4 | ||||
-rw-r--r-- | src/nvim/ui.h | 2 | ||||
-rw-r--r-- | src/nvim/ui_bridge.c | 1 |
5 files changed, 80 insertions, 20 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 85575f1cbe..2b131443d3 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -8,6 +8,7 @@ #include "nvim/memory.h" #include "nvim/map.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/api/ui.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/popupmnu.h" @@ -45,8 +46,8 @@ void remote_ui_disconnect(uint64_t channel_id) xfree(ui); } -void ui_attach(uint64_t channel_id, Integer width, Integer height, - Boolean enable_rgb, Error *err) +void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, + Dictionary options, Error *err) { if (pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(err, Exception, _("UI already attached for channel")); @@ -58,14 +59,11 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height, _("Expected width > 0 and height > 0")); return; } - UIData *data = xmalloc(sizeof(UIData)); - data->channel_id = channel_id; - data->buffer = (Array)ARRAY_DICT_INIT; UI *ui = xcalloc(1, sizeof(UI)); ui->width = (int)width; ui->height = (int)height; - ui->rgb = enable_rgb; - ui->data = data; + ui->rgb = true; + ui->pum_external = false; ui->resize = remote_ui_resize; ui->clear = remote_ui_clear; ui->eol_clear = remote_ui_eol_clear; @@ -90,51 +88,107 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height, ui->set_title = remote_ui_set_title; ui->set_icon = remote_ui_set_icon; ui->event = remote_ui_event; + + for (size_t i = 0; i < options.size; i++) { + ui_set_option(ui, options.items[i].key, options.items[i].value, err); + if (err->set) { + xfree(ui); + return; + } + } + + UIData *data = xmalloc(sizeof(UIData)); + data->channel_id = channel_id; + data->buffer = (Array)ARRAY_DICT_INIT; + ui->data = data; + pmap_put(uint64_t)(connected_uis, channel_id, ui); ui_attach_impl(ui); - return; } -void ui_detach(uint64_t channel_id, Error *err) +/// @deprecated +void ui_attach(uint64_t channel_id, Integer width, Integer height, + Boolean enable_rgb, Error *err) +{ + Dictionary opts = ARRAY_DICT_INIT; + PUT(opts, "rgb", BOOLEAN_OBJ(enable_rgb)); + nvim_ui_attach(channel_id, width, height, opts, err); + api_free_dictionary(opts); +} + +void nvim_ui_detach(uint64_t channel_id, Error *err) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(err, Exception, _("UI is not attached for channel")); + return; } remote_ui_disconnect(channel_id); } -Object ui_try_resize(uint64_t channel_id, Integer width, - Integer height, Error *err) +/// @deprecated +void ui_detach(uint64_t channel_id, Error *err) +{ + nvim_ui_detach(channel_id, err); +} + +void nvim_ui_try_resize(uint64_t channel_id, Integer width, + Integer height, Error *err) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(err, Exception, _("UI is not attached for channel")); + return; } if (width <= 0 || height <= 0) { api_set_error(err, Validation, _("Expected width > 0 and height > 0")); - return NIL; + return; } UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); ui->width = (int)width; ui->height = (int)height; ui_refresh(); - return NIL; } -void ui_set_popupmenu_external(uint64_t channel_id, Boolean external, - Error *error) +/// @deprecated +void ui_try_resize(uint64_t channel_id, Integer width, + Integer height, Error *err) { - // Technically this is not needed right now, - // but futher on we might implement smarter behavior when multiple - // ui:s are attached with different draw modes + nvim_ui_try_resize(channel_id, width, height, err); +} + +void nvim_ui_set_option(uint64_t channel_id, String name, + Object value, Error *error) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(error, Exception, _("UI is not attached for channel")); return; } + UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); + + ui_set_option(ui, name, value, error); + if (!error->set) { + ui_refresh(); + } +} - pum_set_external(external); +static void ui_set_option(UI *ui, String name, Object value, Error *error) { + if (strcmp(name.data, "rgb") == 0) { + if (value.type != kObjectTypeBoolean) { + api_set_error(error, Validation, _("rgb must be a Boolean")); + return; + } + ui->rgb = value.data.boolean; + } else if (strcmp(name.data, "popupmenu_external") == 0) { + if (value.type != kObjectTypeBoolean) { + api_set_error(error, Validation, + _("popupmenu_external must be a Boolean")); + return; + } + ui->pum_external = value.data.boolean; + } else { + api_set_error(error, Validation, _("No such ui option")); + } } static void push_call(UI *ui, char *name, Array args) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 5ed13aa207..bfc03dfb81 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -83,6 +83,7 @@ UI *tui_start(void) UI *ui = xcalloc(1, sizeof(UI)); ui->stop = tui_stop; ui->rgb = p_tgc; + ui->pum_external = false; ui->resize = tui_resize; ui->clear = tui_clear; ui->eol_clear = tui_eol_clear; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 031cdede07..306dd6c43a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -27,6 +27,7 @@ #include "nvim/os/time.h" #include "nvim/os/input.h" #include "nvim/os/signal.h" +#include "nvim/popupmnu.h" #include "nvim/screen.h" #include "nvim/syntax.h" #include "nvim/window.h" @@ -166,15 +167,18 @@ void ui_refresh(void) } int width = INT_MAX, height = INT_MAX; + bool pum_external = true; for (size_t i = 0; i < ui_count; i++) { UI *ui = uis[i]; width = ui->width < width ? ui->width : width; height = ui->height < height ? ui->height : height; + pum_external &= ui->pum_external; } row = col = 0; screen_resize(width, height); + pum_set_external(pum_external); } void ui_resize(int new_width, int new_height) diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 3d568d597a..d14bc5812c 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -15,7 +15,7 @@ typedef struct { typedef struct ui_t UI; struct ui_t { - bool rgb; + bool rgb, pum_external; int width, height; void *data; void (*resize)(UI *ui, int rows, int columns); diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index 6290fb3d87..34b95baf6c 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -31,6 +31,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData)); rv->ui = ui; rv->bridge.rgb = ui->rgb; + rv->bridge.pum_external = ui->pum_external; rv->bridge.stop = ui_bridge_stop; rv->bridge.resize = ui_bridge_resize; rv->bridge.clear = ui_bridge_clear; |