api: generate ui events

This commit is contained in:
Björn Linse
2017-04-29 13:06:14 +02:00
parent d9023b84e6
commit 489d10c57c
10 changed files with 325 additions and 463 deletions

View File

@@ -885,6 +885,24 @@ static void init_type_metadata(Dictionary *metadata)
PUT(*metadata, "types", DICTIONARY_OBJ(types));
}
String copy_string(String str)
{
if (str.data != NULL) {
return (String){ .data = xmemdupz(str.data, str.size), .size = str.size };
} else {
return (String)STRING_INIT;
}
}
Array copy_array(Array array)
{
Array rv = ARRAY_DICT_INIT;
for (size_t i = 0; i < array.size; i++) {
ADD(rv, copy_object(array.items[i]));
}
return rv;
}
/// Creates a deep clone of an object
Object copy_object(Object obj)
{
@@ -896,15 +914,10 @@ Object copy_object(Object obj)
return obj;
case kObjectTypeString:
return STRING_OBJ(cstr_to_string(obj.data.string.data));
return STRING_OBJ(copy_string(obj.data.string));
case kObjectTypeArray: {
Array rv = ARRAY_DICT_INIT;
for (size_t i = 0; i < obj.data.array.size; i++) {
ADD(rv, copy_object(obj.data.array.items[i]));
}
return ARRAY_OBJ(rv);
}
case kObjectTypeArray:
return ARRAY_OBJ(copy_array(obj.data.array));
case kObjectTypeDictionary: {
Dictionary rv = ARRAY_DICT_INIT;

View File

@@ -19,6 +19,7 @@
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "api/ui.c.generated.h"
# include "ui_events_remote.generated.h"
#endif
typedef struct {
@@ -236,100 +237,6 @@ static void push_call(UI *ui, char *name, Array args)
kv_A(data->buffer, kv_size(data->buffer) - 1).data.array = call;
}
static void remote_ui_resize(UI *ui, int width, int height)
{
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(width));
ADD(args, INTEGER_OBJ(height));
push_call(ui, "resize", args);
}
static void remote_ui_clear(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "clear", args);
}
static void remote_ui_eol_clear(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "eol_clear", args);
}
static void remote_ui_cursor_goto(UI *ui, int row, int col)
{
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(row));
ADD(args, INTEGER_OBJ(col));
push_call(ui, "cursor_goto", args);
}
static void remote_ui_update_menu(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "update_menu", args);
}
static void remote_ui_busy_start(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "busy_start", args);
}
static void remote_ui_busy_stop(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "busy_stop", args);
}
static void remote_ui_mouse_on(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "mouse_on", args);
}
static void remote_ui_mouse_off(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "mouse_off", args);
}
static void remote_ui_mode_change(UI *ui, int mode_idx)
{
Array args = ARRAY_DICT_INIT;
char *full_name = shape_table[mode_idx].full_name;
ADD(args, STRING_OBJ(cstr_to_string(full_name)));
ADD(args, INTEGER_OBJ(mode_idx));
push_call(ui, "mode_change", args);
}
static void remote_ui_set_scroll_region(UI *ui, int top, int bot, int left,
int right)
{
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(top));
ADD(args, INTEGER_OBJ(bot));
ADD(args, INTEGER_OBJ(left));
ADD(args, INTEGER_OBJ(right));
push_call(ui, "set_scroll_region", args);
}
static void remote_ui_scroll(UI *ui, int count)
{
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(count));
push_call(ui, "scroll", args);
}
static void remote_ui_mode_info_set(UI *ui, bool guicursor_enabled, Array data)
{
Array args = ARRAY_DICT_INIT;
ADD(args, BOOLEAN_OBJ(guicursor_enabled));
ADD(args, copy_object(ARRAY_OBJ(data)));
push_call(ui, "mode_info_set", args);
}
static void remote_ui_highlight_set(UI *ui, HlAttrs attrs)
{
@@ -372,47 +279,6 @@ static void remote_ui_highlight_set(UI *ui, HlAttrs attrs)
push_call(ui, "highlight_set", args);
}
static void remote_ui_put(UI *ui, uint8_t *data, size_t size)
{
Array args = ARRAY_DICT_INIT;
String str = { .data = xmemdupz(data, size), .size = size };
ADD(args, STRING_OBJ(str));
push_call(ui, "put", args);
}
static void remote_ui_bell(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "bell", args);
}
static void remote_ui_visual_bell(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "visual_bell", args);
}
static void remote_ui_update_fg(UI *ui, int fg)
{
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(fg));
push_call(ui, "update_fg", args);
}
static void remote_ui_update_bg(UI *ui, int bg)
{
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(bg));
push_call(ui, "update_bg", args);
}
static void remote_ui_update_sp(UI *ui, int sp)
{
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(sp));
push_call(ui, "update_sp", args);
}
static void remote_ui_flush(UI *ui)
{
UIData *data = ui->data;
@@ -422,26 +288,6 @@ static void remote_ui_flush(UI *ui)
}
}
static void remote_ui_suspend(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "suspend", args);
}
static void remote_ui_set_title(UI *ui, char *title)
{
Array args = ARRAY_DICT_INIT;
ADD(args, STRING_OBJ(cstr_to_string(title)));
push_call(ui, "set_title", args);
}
static void remote_ui_set_icon(UI *ui, char *icon)
{
Array args = ARRAY_DICT_INIT;
ADD(args, STRING_OBJ(cstr_to_string(icon)));
push_call(ui, "set_icon", args);
}
static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
{
Array my_args = ARRAY_DICT_INIT;

View File

@@ -0,0 +1,42 @@
#ifndef NVIM_API_UI_EVENTS_IN_H
#define NVIM_API_UI_EVENTS_IN_H
// This file is not compiled, just parsed for definitons
#ifdef INCLUDE_GENERATED_DECLARATIONS
#error "don't include this file, include nvim/ui.h"
#endif
#include "nvim/api/private/defs.h"
#include "nvim/func_attr.h"
#include "nvim/ui.h"
void resize(Integer rows, Integer columns);
void clear(void);
void eol_clear(void);
void cursor_goto(Integer row, Integer col);
void mode_info_set(Boolean enabled, Array cursor_styles);
void update_menu(void);
void busy_start(void);
void busy_stop(void);
void mouse_on(void);
void mouse_off(void);
void mode_change(String mode, Integer mode_idx);
void set_scroll_region(Integer top, Integer bot, Integer left, Integer right);
void scroll(Integer count);
void highlight_set(HlAttrs attrs) REMOTE_IMPL BRIDGE_IMPL;
void put(String str);
void bell(void);
void visual_bell(void);
void flush(void) REMOTE_IMPL;
void update_fg(Integer fg);
void update_bg(Integer bg);
void update_sp(Integer sp);
void suspend(void) BRIDGE_IMPL;
void set_title(String title);
void set_icon(String icon);
void popupmenu_show(Array items, Integer selected, Integer row, Integer col) REMOTE_ONLY;
void popupmenu_hide(void) REMOTE_ONLY;
void popupmenu_select(Integer selected) REMOTE_ONLY;
#endif // NVIM_API_UI_EVENTS_IN_H