comparison src/libvterm/src/vterm.c @ 20518:a4652d7ec99f v8.2.0813

patch 8.2.0813: libvterm code is slightly different from upstream Commit: https://github.com/vim/vim/commit/591cec8366e87a172495c362477cbf5de8d399f0 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 22 22:06:06 2020 +0200 patch 8.2.0813: libvterm code is slightly different from upstream Problem: libvterm code is slightly different from upstream. Solution: Use upstream text to avoid future merge problems. Mainly comment style changes.
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 May 2020 22:15:04 +0200
parents 747a270eb1db
children f93337ae0612
comparison
equal deleted inserted replaced
20517:a7c6cd0d7ba0 20518:a4652d7ec99f
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "utf8.h" 11 #include "utf8.h"
12 12
13 /////////////////// 13 /*****************
14 // API functions // 14 * API functions *
15 /////////////////// 15 *****************/
16 16
17 static void *default_malloc(size_t size, void *allocdata UNUSED) 17 static void *default_malloc(size_t size, void *allocdata UNUSED)
18 { 18 {
19 void *ptr = malloc(size); 19 void *ptr = malloc(size);
20 if(ptr) 20 if(ptr)
37 return vterm_new_with_allocator(rows, cols, &default_allocator, NULL); 37 return vterm_new_with_allocator(rows, cols, &default_allocator, NULL);
38 } 38 }
39 39
40 VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata) 40 VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata)
41 { 41 {
42 // Need to bootstrap using the allocator function directly 42 /* Need to bootstrap using the allocator function directly */
43 VTerm *vt = (*funcs->malloc)(sizeof(VTerm), allocdata); 43 VTerm *vt = (*funcs->malloc)(sizeof(VTerm), allocdata);
44 44
45 if (vt == NULL) 45 if (vt == NULL)
46 return NULL; 46 return NULL;
47 vt->allocator = funcs; 47 vt->allocator = funcs;
267 case VTERM_ATTR_FOREGROUND: return VTERM_VALUETYPE_COLOR; 267 case VTERM_ATTR_FOREGROUND: return VTERM_VALUETYPE_COLOR;
268 case VTERM_ATTR_BACKGROUND: return VTERM_VALUETYPE_COLOR; 268 case VTERM_ATTR_BACKGROUND: return VTERM_VALUETYPE_COLOR;
269 269
270 case VTERM_N_ATTRS: return 0; 270 case VTERM_N_ATTRS: return 0;
271 } 271 }
272 return 0; // UNREACHABLE 272 return 0; /* UNREACHABLE */
273 } 273 }
274 274
275 VTermValueType vterm_get_prop_type(VTermProp prop) 275 VTermValueType vterm_get_prop_type(VTermProp prop)
276 { 276 {
277 switch(prop) { 277 switch(prop) {
285 case VTERM_PROP_MOUSE: return VTERM_VALUETYPE_INT; 285 case VTERM_PROP_MOUSE: return VTERM_VALUETYPE_INT;
286 case VTERM_PROP_CURSORCOLOR: return VTERM_VALUETYPE_STRING; 286 case VTERM_PROP_CURSORCOLOR: return VTERM_VALUETYPE_STRING;
287 287
288 case VTERM_N_PROPS: return 0; 288 case VTERM_N_PROPS: return 0;
289 } 289 }
290 return 0; // UNREACHABLE 290 return 0; /* UNREACHABLE */
291 } 291 }
292 292
293 void vterm_scroll_rect(VTermRect rect, 293 void vterm_scroll_rect(VTermRect rect,
294 int downward, 294 int downward,
295 int rightward, 295 int rightward,
300 VTermRect src; 300 VTermRect src;
301 VTermRect dest; 301 VTermRect dest;
302 302
303 if(abs(downward) >= rect.end_row - rect.start_row || 303 if(abs(downward) >= rect.end_row - rect.start_row ||
304 abs(rightward) >= rect.end_col - rect.start_col) { 304 abs(rightward) >= rect.end_col - rect.start_col) {
305 // Scroll more than area; just erase the lot 305 /* Scroll more than area; just erase the lot */
306 (*eraserect)(rect, 0, user); 306 (*eraserect)(rect, 0, user);
307 return; 307 return;
308 } 308 }
309 309
310 if(rightward >= 0) { 310 if(rightward >= 0) {
311 // rect: [XXX................] 311 /* rect: [XXX................]
312 // src: [----------------] 312 * src: [----------------]
313 // dest: [----------------] 313 * dest: [----------------]
314 */
314 dest.start_col = rect.start_col; 315 dest.start_col = rect.start_col;
315 dest.end_col = rect.end_col - rightward; 316 dest.end_col = rect.end_col - rightward;
316 src.start_col = rect.start_col + rightward; 317 src.start_col = rect.start_col + rightward;
317 src.end_col = rect.end_col; 318 src.end_col = rect.end_col;
318 } 319 }
319 else { 320 else {
320 // rect: [................XXX] 321 /* rect: [................XXX]
321 // src: [----------------] 322 * src: [----------------]
322 // dest: [----------------] 323 * dest: [----------------]
324 */
323 int leftward = -rightward; 325 int leftward = -rightward;
324 dest.start_col = rect.start_col + leftward; 326 dest.start_col = rect.start_col + leftward;
325 dest.end_col = rect.end_col; 327 dest.end_col = rect.end_col;
326 src.start_col = rect.start_col; 328 src.start_col = rect.start_col;
327 src.end_col = rect.end_col - leftward; 329 src.end_col = rect.end_col - leftward;
373 if(downward < 0) { 375 if(downward < 0) {
374 init_row = dest.end_row - 1; 376 init_row = dest.end_row - 1;
375 test_row = dest.start_row - 1; 377 test_row = dest.start_row - 1;
376 inc_row = -1; 378 inc_row = -1;
377 } 379 }
378 else { 380 else /* downward >= 0 */ {
379 // downward >= 0
380 init_row = dest.start_row; 381 init_row = dest.start_row;
381 test_row = dest.end_row; 382 test_row = dest.end_row;
382 inc_row = +1; 383 inc_row = +1;
383 } 384 }
384 385
385 if(rightward < 0) { 386 if(rightward < 0) {
386 init_col = dest.end_col - 1; 387 init_col = dest.end_col - 1;
387 test_col = dest.start_col - 1; 388 test_col = dest.start_col - 1;
388 inc_col = -1; 389 inc_col = -1;
389 } 390 }
390 else { 391 else /* rightward >= 0 */ {
391 // rightward >= 0
392 init_col = dest.start_col; 392 init_col = dest.start_col;
393 test_col = dest.end_col; 393 test_col = dest.end_col;
394 inc_col = +1; 394 inc_col = +1;
395 } 395 }
396 396