comparison src/libvterm/include/vterm.h @ 30880:82336c3b679d v9.0.0774

patch 9.0.0774: the libvterm code is outdated Commit: https://github.com/vim/vim/commit/6a12d26f3404e45ce25cf9152857e355b28f392a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 16 19:26:52 2022 +0100 patch 9.0.0774: the libvterm code is outdated Problem: The libvterm code is outdated. Solution: Include libvterm changes from revision 802 to 817. Revert some changes made for C89.
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Oct 2022 20:30:07 +0200
parents 2d2758ffd959
children ac9464a32606
comparison
equal deleted inserted replaced
30879:2db86b9d26df 30880:82336c3b679d
10 10
11 #include <stdlib.h> 11 #include <stdlib.h>
12 12
13 #include "vterm_keycodes.h" 13 #include "vterm_keycodes.h"
14 14
15 // VIM: use TRUE and FALSE instead of true and false
15 #define TRUE 1 16 #define TRUE 1
16 #define FALSE 0 17 #define FALSE 0
17 18
18 // from stdint.h 19 // VIM: from stdint.h
19 typedef unsigned char uint8_t; 20 typedef unsigned char uint8_t;
20 typedef unsigned short uint16_t; 21 typedef unsigned short uint16_t;
21 typedef unsigned int uint32_t; 22 typedef unsigned int uint32_t;
22 23
23 #define VTERM_VERSION_MAJOR 0 24 #define VTERM_VERSION_MAJOR 0
24 #define VTERM_VERSION_MINOR 2 25 #define VTERM_VERSION_MINOR 3
25 26
26 #define VTERM_CHECK_VERSION \ 27 #define VTERM_CHECK_VERSION \
27 vterm_check_version(VTERM_VERSION_MAJOR, VTERM_VERSION_MINOR) 28 vterm_check_version(VTERM_VERSION_MAJOR, VTERM_VERSION_MINOR)
28 29
29 /* Any cell can contain at most one basic printing character and 5 combining 30 /* Any cell can contain at most one basic printing character and 5 combining
129 * Mask that can be used to extract the default foreground/background bit. 130 * Mask that can be used to extract the default foreground/background bit.
130 */ 131 */
131 VTERM_COLOR_DEFAULT_MASK = 0x06, 132 VTERM_COLOR_DEFAULT_MASK = 0x06,
132 133
133 /** 134 /**
134 * If set, indicates that the color is invalid. 135 * VIM: If set, indicates that the color is invalid.
135 */ 136 */
136 VTERM_COLOR_INVALID = 0x08 137 VTERM_COLOR_INVALID = 0x08
137 } VTermColorType; 138 } VTermColorType;
138 139
139 /** 140 /**
170 * Returns true if the VTERM_COLOR_INVALID `type` flag is set, indicating 171 * Returns true if the VTERM_COLOR_INVALID `type` flag is set, indicating
171 * that the given VTermColor instance is an invalid color. 172 * that the given VTermColor instance is an invalid color.
172 */ 173 */
173 #define VTERM_COLOR_IS_INVALID(col) (!!((col)->type & VTERM_COLOR_INVALID)) 174 #define VTERM_COLOR_IS_INVALID(col) (!!((col)->type & VTERM_COLOR_INVALID))
174 175
176 // VIM: this was a union, but that doesn't always work.
175 typedef struct { 177 typedef struct {
176 /** 178 /**
177 * Tag indicating which member is actually valid. 179 * Tag indicating which member is actually valid.
178 * Please use the `VTERM_COLOR_IS_*` test macros to check whether a 180 * Please use the `VTERM_COLOR_IS_*` test macros to check whether a
179 * particular type flag is set. 181 * particular type flag is set.
235 VTERM_ATTR_CONCEAL, // bool: 8, 28 237 VTERM_ATTR_CONCEAL, // bool: 8, 28
236 VTERM_ATTR_STRIKE, // bool: 9, 29 238 VTERM_ATTR_STRIKE, // bool: 9, 29
237 VTERM_ATTR_FONT, // number: 10-19 239 VTERM_ATTR_FONT, // number: 10-19
238 VTERM_ATTR_FOREGROUND, // color: 30-39 90-97 240 VTERM_ATTR_FOREGROUND, // color: 30-39 90-97
239 VTERM_ATTR_BACKGROUND, // color: 40-49 100-107 241 VTERM_ATTR_BACKGROUND, // color: 40-49 100-107
242 VTERM_ATTR_SMALL, // bool: 73, 74, 75
243 VTERM_ATTR_BASELINE, // number: 73, 74, 75
240 244
241 VTERM_N_ATTRS 245 VTERM_N_ATTRS
242 } VTermAttr; 246 } VTermAttr;
243 247
244 typedef enum { 248 typedef enum {
249 VTERM_PROP_TITLE, // string 253 VTERM_PROP_TITLE, // string
250 VTERM_PROP_ICONNAME, // string 254 VTERM_PROP_ICONNAME, // string
251 VTERM_PROP_REVERSE, // bool 255 VTERM_PROP_REVERSE, // bool
252 VTERM_PROP_CURSORSHAPE, // number 256 VTERM_PROP_CURSORSHAPE, // number
253 VTERM_PROP_MOUSE, // number 257 VTERM_PROP_MOUSE, // number
254 VTERM_PROP_CURSORCOLOR, // string 258 VTERM_PROP_CURSORCOLOR, // VIM - string
255 259
256 VTERM_N_PROPS 260 VTERM_N_PROPS
257 } VTermProp; 261 } VTermProp;
258 262
259 enum { 263 enum {
310 * by the allocator. */ 314 * by the allocator. */
311 void *(*malloc)(size_t size, void *allocdata); 315 void *(*malloc)(size_t size, void *allocdata);
312 void (*free)(void *ptr, void *allocdata); 316 void (*free)(void *ptr, void *allocdata);
313 } VTermAllocatorFunctions; 317 } VTermAllocatorFunctions;
314 318
315 /* A convenient shortcut for default cases */
316 void vterm_check_version(int major, int minor); 319 void vterm_check_version(int major, int minor);
317 320
318 struct VTermBuilder { 321 struct VTermBuilder {
319 int ver; /* currently unused but reserved for some sort of ABI version flag */ 322 int ver; /* currently unused but reserved for some sort of ABI version flag */
320 323
331 VTerm *vterm_build(const struct VTermBuilder *builder); 334 VTerm *vterm_build(const struct VTermBuilder *builder);
332 335
333 /* A convenient shortcut for default cases */ 336 /* A convenient shortcut for default cases */
334 // Allocate and initialize a new terminal with default allocators. 337 // Allocate and initialize a new terminal with default allocators.
335 VTerm *vterm_new(int rows, int cols); 338 VTerm *vterm_new(int rows, int cols);
336
337 /* These shortcuts are generally discouraged in favour of just using vterm_build() */ 339 /* These shortcuts are generally discouraged in favour of just using vterm_build() */
338 340
339 // Allocate and initialize a new terminal with specified allocators. 341 // Allocate and initialize a new terminal with specified allocators.
340 VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata); 342 VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata);
341 343
394 396
395 #define CSI_ARG_HAS_MORE(a) ((a) & CSI_ARG_FLAG_MORE) 397 #define CSI_ARG_HAS_MORE(a) ((a) & CSI_ARG_FLAG_MORE)
396 #define CSI_ARG(a) ((a) & CSI_ARG_MASK) 398 #define CSI_ARG(a) ((a) & CSI_ARG_MASK)
397 399
398 /* Can't use -1 to indicate a missing argument; use this instead */ 400 /* Can't use -1 to indicate a missing argument; use this instead */
401 // VIM: changed 31 to 30 to avoid an overflow warning
399 #define CSI_ARG_MISSING ((1<<30)-1) 402 #define CSI_ARG_MISSING ((1<<30)-1)
400 403
401 #define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING) 404 #define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING)
402 #define CSI_ARG_OR(a,def) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a)) 405 #define CSI_ARG_OR(a,def) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a))
403 #define CSI_ARG_COUNT(a) (CSI_ARG(a) == CSI_ARG_MISSING || CSI_ARG(a) == 0 ? 1 : CSI_ARG(a)) 406 #define CSI_ARG_COUNT(a) (CSI_ARG(a) == CSI_ARG_MISSING || CSI_ARG(a) == 0 ? 1 : CSI_ARG(a))
434 // was accepted, 0 otherwise. 437 // was accepted, 0 otherwise.
435 int (*settermprop)(VTermProp prop, VTermValue *val, void *user); 438 int (*settermprop)(VTermProp prop, VTermValue *val, void *user);
436 int (*bell)(void *user); 439 int (*bell)(void *user);
437 int (*resize)(int rows, int cols, VTermStateFields *fields, void *user); 440 int (*resize)(int rows, int cols, VTermStateFields *fields, void *user);
438 int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user); 441 int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user);
442 int (*sb_clear)(void *user);
439 } VTermStateCallbacks; 443 } VTermStateCallbacks;
440 444
445 // VIM: added
441 typedef struct { 446 typedef struct {
442 VTermPos pos; 447 VTermPos pos;
443 int buttons; 448 int buttons;
444 #define MOUSE_BUTTON_LEFT 0x01 449 #define MOUSE_BUTTON_LEFT 0x01
445 #define MOUSE_BUTTON_MIDDLE 0x02 450 #define MOUSE_BUTTON_MIDDLE 0x02
476 481
477 // Initialize the state. 482 // Initialize the state.
478 void vterm_state_reset(VTermState *state, int hard); 483 void vterm_state_reset(VTermState *state, int hard);
479 484
480 void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos); 485 void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos);
486 // VIM: added
481 void vterm_state_get_mousestate(const VTermState *state, VTermMouseState *mousestate); 487 void vterm_state_get_mousestate(const VTermState *state, VTermMouseState *mousestate);
482 void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg); 488 void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg);
483 void vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col); 489 void vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col);
484 void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg); 490 void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg);
485 void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col); 491 void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col);
520 unsigned int conceal : 1; 526 unsigned int conceal : 1;
521 unsigned int strike : 1; 527 unsigned int strike : 1;
522 unsigned int font : 4; /* 0 to 9 */ 528 unsigned int font : 4; /* 0 to 9 */
523 unsigned int dwl : 1; /* On a DECDWL or DECDHL line */ 529 unsigned int dwl : 1; /* On a DECDWL or DECDHL line */
524 unsigned int dhl : 2; /* On a DECDHL line (1=top 2=bottom) */ 530 unsigned int dhl : 2; /* On a DECDHL line (1=top 2=bottom) */
531 unsigned int small : 1;
532 unsigned int baseline : 2;
525 } VTermScreenCellAttrs; 533 } VTermScreenCellAttrs;
526 534
527 enum { 535 enum {
528 VTERM_UNDERLINE_OFF, 536 VTERM_UNDERLINE_OFF,
529 VTERM_UNDERLINE_SINGLE, 537 VTERM_UNDERLINE_SINGLE,
530 VTERM_UNDERLINE_DOUBLE, 538 VTERM_UNDERLINE_DOUBLE,
531 VTERM_UNDERLINE_CURLY, 539 VTERM_UNDERLINE_CURLY,
540 };
541
542 enum {
543 VTERM_BASELINE_NORMAL,
544 VTERM_BASELINE_RAISE,
545 VTERM_BASELINE_LOWER,
532 }; 546 };
533 547
534 typedef struct { 548 typedef struct {
535 uint32_t chars[VTERM_MAX_CHARS_PER_CELL]; 549 uint32_t chars[VTERM_MAX_CHARS_PER_CELL];
536 char width; 550 char width;
549 // A line was pushed off the top of the window. 563 // A line was pushed off the top of the window.
550 // "cells[cols]" contains the cells of that line. 564 // "cells[cols]" contains the cells of that line.
551 // Return value is unused. 565 // Return value is unused.
552 int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user); 566 int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user);
553 int (*sb_popline)(int cols, VTermScreenCell *cells, void *user); 567 int (*sb_popline)(int cols, VTermScreenCell *cells, void *user);
568 int (*sb_clear)(void* user);
554 } VTermScreenCallbacks; 569 } VTermScreenCallbacks;
555 570
556 // Return the screen of the vterm. 571 // Return the screen of the vterm.
557 VTermScreen *vterm_obtain_screen(VTerm *vt); 572 VTermScreen *vterm_obtain_screen(VTerm *vt);
558 573
563 void vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *user); 578 void vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *user);
564 void *vterm_screen_get_cbdata(VTermScreen *screen); 579 void *vterm_screen_get_cbdata(VTermScreen *screen);
565 580
566 void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermStateFallbacks *fallbacks, void *user); 581 void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermStateFallbacks *fallbacks, void *user);
567 void *vterm_screen_get_unrecognised_fbdata(VTermScreen *screen); 582 void *vterm_screen_get_unrecognised_fbdata(VTermScreen *screen);
583
584 void vterm_screen_enable_reflow(VTermScreen *screen, int reflow);
585
586 // Back-compat alias for the brief time it was in 0.3-RC1
587 #define vterm_screen_set_reflow vterm_screen_enable_reflow
568 588
569 // Enable support for using the alternate screen if "altscreen" is non-zero. 589 // Enable support for using the alternate screen if "altscreen" is non-zero.
570 // Before that switching to the alternate screen won't work. 590 // Before that switching to the alternate screen won't work.
571 // Calling with "altscreen" zero has no effect. 591 // Calling with "altscreen" zero has no effect.
572 void vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen); 592 void vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen);
604 VTERM_ATTR_STRIKE_MASK = 1 << 5, 624 VTERM_ATTR_STRIKE_MASK = 1 << 5,
605 VTERM_ATTR_FONT_MASK = 1 << 6, 625 VTERM_ATTR_FONT_MASK = 1 << 6,
606 VTERM_ATTR_FOREGROUND_MASK = 1 << 7, 626 VTERM_ATTR_FOREGROUND_MASK = 1 << 7,
607 VTERM_ATTR_BACKGROUND_MASK = 1 << 8, 627 VTERM_ATTR_BACKGROUND_MASK = 1 << 8,
608 VTERM_ATTR_CONCEAL_MASK = 1 << 9, 628 VTERM_ATTR_CONCEAL_MASK = 1 << 9,
609 629 VTERM_ATTR_SMALL_MASK = 1 << 10,
610 VTERM_ALL_ATTRS_MASK = (1 << 10) - 1 630 VTERM_ATTR_BASELINE_MASK = 1 << 11,
631
632 VTERM_ALL_ATTRS_MASK = (1 << 12) - 1
611 } VTermAttrMask; 633 } VTermAttrMask;
612 634
613 int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs); 635 int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs);
614 636
615 int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell); 637 int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell);