6
6
#include <assert.h>
7
7
8
8
#include "nvim/vim.h"
9
+
#include "nvim/log.h"
10
+
#include "nvim/map.h"
9
11
#include "nvim/ui_client.h"
10
12
#include "nvim/api/private/helpers.h"
11
13
#include "nvim/msgpack_rpc/channel.h"
12
14
#include "nvim/api/private/dispatch.h"
13
15
#include "nvim/ui.h"
16
+
#include "nvim/highlight.h"
17
+
#include "nvim/screen.h"
18
+
19
+
static Map(String, ApiRedrawWrapper) redraw_methods = MAP_INIT;
20
+
21
+
static void add_redraw_event_handler(String method, ApiRedrawWrapper handler)
22
+
{
23
+
map_put(String, ApiRedrawWrapper)(&redraw_methods, method, handler);
24
+
}
14
25
15
26
void ui_client_init(uint64_t chan)
16
27
{
@@ -68,3 +79,106 @@ void ui_client_execute(uint64_t chan)
68
79
69
80
getout(0);
70
81
}
82
+
83
+
/// @param name Redraw method name
84
+
/// @param name_len name size (includes terminating NUL)
85
+
ApiRedrawWrapper get_redraw_event_handler(const char *name, size_t name_len, Error *error)
86
+
{
87
+
String m = { .data = (char *)name, .size = name_len };
88
+
ApiRedrawWrapper rv =
89
+
map_get(String, ApiRedrawWrapper)(&redraw_methods, m);
90
+
91
+
if (!rv) {
92
+
api_set_error(error, kErrorTypeException, "Invalid method: %.*s",
93
+
m.size > 0 ? (int)m.size : (int)sizeof("<empty>"),
94
+
m.size > 0 ? m.data : "<empty>");
95
+
}
96
+
return rv;
97
+
}
98
+
99
+
static HlAttrs redraw_dict2hlattrs(Dictionary redraw_dict, bool rgb)
100
+
{
101
+
Error err = ERROR_INIT;
102
+
Dict(highlight) dict = { 0 };
103
+
if (!api_dict_to_keydict(&dict, KeyDict_highlight_get_field, redraw_dict, &err)) {
104
+
// TODO(bfredl): log "err"
105
+
return HLATTRS_INIT;
106
+
}
107
+
return dict2hlattrs(&dict, true, NULL, &err);
108
+
}
109
+
110
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
111
+
#include "ui_events_redraw.generated.h"
112
+
#endif
113
+
114
+
void ui_redraw_event_grid_line(Array args)
115
+
{
116
+
Integer grid = args.items[0].data.integer;
117
+
Integer row = args.items[1].data.integer;
118
+
Integer startcol = args.items[2].data.integer;
119
+
Array cells = args.items[3].data.array;
120
+
Integer endcol, clearcol, clearattr;
121
+
// TODO(hlpr98): Accomodate other LineFlags when included in grid_line
122
+
LineFlags lineflags = 0;
123
+
schar_T *chunk;
124
+
sattr_T *attrs;
125
+
size_t size_of_cells = cells.size;
126
+
size_t no_of_cells = size_of_cells;
127
+
endcol = startcol;
128
+
129
+
// checking if clearcol > endcol
130
+
if (!STRCMP(cells.items[size_of_cells-1].data.array
131
+
.items[0].data.string.data, " ")
132
+
&& cells.items[size_of_cells-1].data.array.size == 3) {
133
+
no_of_cells = size_of_cells - 1;
134
+
}
135
+
136
+
// getting endcol
137
+
for (size_t i = 0; i < no_of_cells; i++) {
138
+
endcol++;
139
+
if (cells.items[i].data.array.size == 3) {
140
+
endcol += cells.items[i].data.array.items[2].data.integer - 1;
141
+
}
142
+
}
143
+
144
+
if (!STRCMP(cells.items[size_of_cells-1].data.array
145
+
.items[0].data.string.data, " ")
146
+
&& cells.items[size_of_cells-1].data.array.size == 3) {
147
+
clearattr = cells.items[size_of_cells-1].data.array.items[1].data.integer;
148
+
clearcol = endcol + cells.items[size_of_cells-1].data.array
149
+
.items[2].data.integer;
150
+
} else {
151
+
clearattr = 0;
152
+
clearcol = endcol;
153
+
}
154
+
155
+
size_t ncells = (size_t)(endcol - startcol);
156
+
chunk = xmalloc(ncells * sizeof(schar_T) + 1);
157
+
attrs = xmalloc(ncells * sizeof(sattr_T) + 1);
158
+
159
+
size_t j = 0;
160
+
size_t k = 0;
161
+
for (size_t i = 0; i < no_of_cells; i++) {
162
+
STRCPY(chunk[j++], cells.items[i].data.array.items[0].data.string.data);
163
+
if (cells.items[i].data.array.size == 3) {
164
+
// repeat present
165
+
for (size_t i_intr = 1;
166
+
i_intr < (size_t)cells.items[i].data.array.items[2].data.integer;
167
+
i_intr++) {
168
+
STRCPY(chunk[j++], cells.items[i].data.array.items[0].data.string.data);
169
+
attrs[k++] = (sattr_T)cells.items[i].data.array.items[1].data.integer;
170
+
}
171
+
} else if (cells.items[i].data.array.size == 2) {
172
+
// repeat = 1 but attrs != last_hl
173
+
attrs[k++] = (sattr_T)cells.items[i].data.array.items[1].data.integer;
174
+
}
175
+
if (j > k) {
176
+
// attrs == last_hl
177
+
attrs[k] = attrs[k-1];
178
+
k++;
179
+
}
180
+
}
181
+
182
+
ui_call_raw_line(grid, row, startcol, endcol, clearcol, clearattr, lineflags,
183
+
(const schar_T *)chunk, (const sattr_T *)attrs);
184
+
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4