mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api/ui: use ui options instead of one method per feature
Use new nvim_ui_ prefix to avoid breaking change.
This commit is contained in:
parent
999af47be8
commit
e968d72cae
@ -8,6 +8,7 @@
|
|||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/map.h"
|
#include "nvim/map.h"
|
||||||
#include "nvim/msgpack_rpc/channel.h"
|
#include "nvim/msgpack_rpc/channel.h"
|
||||||
|
#include "nvim/api/ui.h"
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/popupmnu.h"
|
#include "nvim/popupmnu.h"
|
||||||
@ -45,8 +46,8 @@ void remote_ui_disconnect(uint64_t channel_id)
|
|||||||
xfree(ui);
|
xfree(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_attach(uint64_t channel_id, Integer width, Integer height,
|
void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
|
||||||
Boolean enable_rgb, Error *err)
|
Dictionary options, Error *err)
|
||||||
{
|
{
|
||||||
if (pmap_has(uint64_t)(connected_uis, channel_id)) {
|
if (pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(err, Exception, _("UI already attached for channel"));
|
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"));
|
_("Expected width > 0 and height > 0"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UIData *data = xmalloc(sizeof(UIData));
|
|
||||||
data->channel_id = channel_id;
|
|
||||||
data->buffer = (Array)ARRAY_DICT_INIT;
|
|
||||||
UI *ui = xcalloc(1, sizeof(UI));
|
UI *ui = xcalloc(1, sizeof(UI));
|
||||||
ui->width = (int)width;
|
ui->width = (int)width;
|
||||||
ui->height = (int)height;
|
ui->height = (int)height;
|
||||||
ui->rgb = enable_rgb;
|
ui->rgb = true;
|
||||||
ui->data = data;
|
ui->pum_external = false;
|
||||||
ui->resize = remote_ui_resize;
|
ui->resize = remote_ui_resize;
|
||||||
ui->clear = remote_ui_clear;
|
ui->clear = remote_ui_clear;
|
||||||
ui->eol_clear = remote_ui_eol_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_title = remote_ui_set_title;
|
||||||
ui->set_icon = remote_ui_set_icon;
|
ui->set_icon = remote_ui_set_icon;
|
||||||
ui->event = remote_ui_event;
|
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);
|
pmap_put(uint64_t)(connected_uis, channel_id, ui);
|
||||||
ui_attach_impl(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)) {
|
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(err, Exception, _("UI is not attached for channel"));
|
api_set_error(err, Exception, _("UI is not attached for channel"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
remote_ui_disconnect(channel_id);
|
remote_ui_disconnect(channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object ui_try_resize(uint64_t channel_id, Integer width,
|
/// @deprecated
|
||||||
Integer height, Error *err)
|
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)) {
|
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(err, Exception, _("UI is not attached for channel"));
|
api_set_error(err, Exception, _("UI is not attached for channel"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
api_set_error(err, Validation,
|
api_set_error(err, Validation,
|
||||||
_("Expected width > 0 and height > 0"));
|
_("Expected width > 0 and height > 0"));
|
||||||
return NIL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
||||||
ui->width = (int)width;
|
ui->width = (int)width;
|
||||||
ui->height = (int)height;
|
ui->height = (int)height;
|
||||||
ui_refresh();
|
ui_refresh();
|
||||||
return NIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_set_popupmenu_external(uint64_t channel_id, Boolean external,
|
/// @deprecated
|
||||||
Error *error)
|
void ui_try_resize(uint64_t channel_id, Integer width,
|
||||||
|
Integer height, Error *err)
|
||||||
{
|
{
|
||||||
// Technically this is not needed right now,
|
nvim_ui_try_resize(channel_id, width, height, err);
|
||||||
// but futher on we might implement smarter behavior when multiple
|
}
|
||||||
// ui:s are attached with different draw modes
|
|
||||||
|
void nvim_ui_set_option(uint64_t channel_id, String name,
|
||||||
|
Object value, Error *error) {
|
||||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
api_set_error(error, Exception, _("UI is not attached for channel"));
|
api_set_error(error, Exception, _("UI is not attached for channel"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
||||||
|
|
||||||
pum_set_external(external);
|
ui_set_option(ui, name, value, error);
|
||||||
|
if (!error->set) {
|
||||||
|
ui_refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
static void push_call(UI *ui, char *name, Array args)
|
||||||
|
@ -83,6 +83,7 @@ UI *tui_start(void)
|
|||||||
UI *ui = xcalloc(1, sizeof(UI));
|
UI *ui = xcalloc(1, sizeof(UI));
|
||||||
ui->stop = tui_stop;
|
ui->stop = tui_stop;
|
||||||
ui->rgb = p_tgc;
|
ui->rgb = p_tgc;
|
||||||
|
ui->pum_external = false;
|
||||||
ui->resize = tui_resize;
|
ui->resize = tui_resize;
|
||||||
ui->clear = tui_clear;
|
ui->clear = tui_clear;
|
||||||
ui->eol_clear = tui_eol_clear;
|
ui->eol_clear = tui_eol_clear;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/os/input.h"
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/os/signal.h"
|
#include "nvim/os/signal.h"
|
||||||
|
#include "nvim/popupmnu.h"
|
||||||
#include "nvim/screen.h"
|
#include "nvim/screen.h"
|
||||||
#include "nvim/syntax.h"
|
#include "nvim/syntax.h"
|
||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
@ -166,15 +167,18 @@ void ui_refresh(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int width = INT_MAX, height = INT_MAX;
|
int width = INT_MAX, height = INT_MAX;
|
||||||
|
bool pum_external = true;
|
||||||
|
|
||||||
for (size_t i = 0; i < ui_count; i++) {
|
for (size_t i = 0; i < ui_count; i++) {
|
||||||
UI *ui = uis[i];
|
UI *ui = uis[i];
|
||||||
width = ui->width < width ? ui->width : width;
|
width = ui->width < width ? ui->width : width;
|
||||||
height = ui->height < height ? ui->height : height;
|
height = ui->height < height ? ui->height : height;
|
||||||
|
pum_external &= ui->pum_external;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = col = 0;
|
row = col = 0;
|
||||||
screen_resize(width, height);
|
screen_resize(width, height);
|
||||||
|
pum_set_external(pum_external);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_resize(int new_width, int new_height)
|
void ui_resize(int new_width, int new_height)
|
||||||
|
@ -15,7 +15,7 @@ typedef struct {
|
|||||||
typedef struct ui_t UI;
|
typedef struct ui_t UI;
|
||||||
|
|
||||||
struct ui_t {
|
struct ui_t {
|
||||||
bool rgb;
|
bool rgb, pum_external;
|
||||||
int width, height;
|
int width, height;
|
||||||
void *data;
|
void *data;
|
||||||
void (*resize)(UI *ui, int rows, int columns);
|
void (*resize)(UI *ui, int rows, int columns);
|
||||||
|
@ -31,6 +31,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
|
|||||||
UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData));
|
UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData));
|
||||||
rv->ui = ui;
|
rv->ui = ui;
|
||||||
rv->bridge.rgb = ui->rgb;
|
rv->bridge.rgb = ui->rgb;
|
||||||
|
rv->bridge.pum_external = ui->pum_external;
|
||||||
rv->bridge.stop = ui_bridge_stop;
|
rv->bridge.stop = ui_bridge_stop;
|
||||||
rv->bridge.resize = ui_bridge_resize;
|
rv->bridge.resize = ui_bridge_resize;
|
||||||
rv->bridge.clear = ui_bridge_clear;
|
rv->bridge.clear = ui_bridge_clear;
|
||||||
|
Loading…
Reference in New Issue
Block a user