Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * NOTE: This is a MODIFIED version of libvterm, see the README file. |
| 3 | */ |
| 4 | #ifndef __VTERM_H__ |
| 5 | #define __VTERM_H__ |
| 6 | |
| 7 | #ifdef __cplusplus |
| 8 | extern "C" { |
| 9 | #endif |
| 10 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 11 | #include <stdlib.h> |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 12 | |
| 13 | #include "vterm_keycodes.h" |
| 14 | |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 15 | // VIM: use TRUE and FALSE instead of true and false |
Bram Moolenaar | b2a76ec | 2017-07-25 21:34:46 +0200 | [diff] [blame] | 16 | #define TRUE 1 |
| 17 | #define FALSE 0 |
| 18 | |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 19 | // VIM: from stdint.h |
Bram Moolenaar | 607985a | 2017-07-28 17:04:15 +0200 | [diff] [blame] | 20 | typedef unsigned char uint8_t; |
Bram Moolenaar | 7da3415 | 2021-11-24 19:30:55 +0000 | [diff] [blame] | 21 | typedef unsigned short uint16_t; |
Bram Moolenaar | 607985a | 2017-07-28 17:04:15 +0200 | [diff] [blame] | 22 | typedef unsigned int uint32_t; |
| 23 | |
Bram Moolenaar | 6fc3b59 | 2020-05-17 22:27:55 +0200 | [diff] [blame] | 24 | #define VTERM_VERSION_MAJOR 0 |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 25 | #define VTERM_VERSION_MINOR 3 |
Bram Moolenaar | 6fc3b59 | 2020-05-17 22:27:55 +0200 | [diff] [blame] | 26 | |
| 27 | #define VTERM_CHECK_VERSION \ |
| 28 | vterm_check_version(VTERM_VERSION_MAJOR, VTERM_VERSION_MINOR) |
| 29 | |
Bram Moolenaar | 501e777 | 2022-10-16 14:35:46 +0100 | [diff] [blame] | 30 | /* Any cell can contain at most one basic printing character and 5 combining |
| 31 | * characters. This number could be changed but will be ABI-incompatible if |
| 32 | * you do */ |
| 33 | #define VTERM_MAX_CHARS_PER_CELL 6 |
| 34 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 35 | typedef struct VTerm VTerm; |
| 36 | typedef struct VTermState VTermState; |
| 37 | typedef struct VTermScreen VTermScreen; |
| 38 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 39 | // Specifies a screen point. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 40 | typedef struct { |
| 41 | int row; |
| 42 | int col; |
| 43 | } VTermPos; |
| 44 | |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 45 | /* some small utility functions; we can just keep these static here */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Order points by on-screen flow order: |
| 49 | * Return < 0 if "a" is before "b" |
| 50 | * Return 0 if "a" and "b" are equal |
| 51 | * Return > 0 if "a" is after "b". |
| 52 | */ |
| 53 | int vterm_pos_cmp(VTermPos a, VTermPos b); |
| 54 | |
| 55 | #if defined(DEFINE_INLINES) || USE_INLINE |
| 56 | INLINE int vterm_pos_cmp(VTermPos a, VTermPos b) |
| 57 | { |
| 58 | return (a.row == b.row) ? a.col - b.col : a.row - b.row; |
| 59 | } |
| 60 | #endif |
| 61 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 62 | // Specifies a rectangular screen area. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 63 | typedef struct { |
| 64 | int start_row; |
| 65 | int end_row; |
| 66 | int start_col; |
| 67 | int end_col; |
| 68 | } VTermRect; |
| 69 | |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 70 | /* true if the rect contains the point */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 71 | int vterm_rect_contains(VTermRect r, VTermPos p); |
| 72 | |
| 73 | #if defined(DEFINE_INLINES) || USE_INLINE |
| 74 | INLINE int vterm_rect_contains(VTermRect r, VTermPos p) |
| 75 | { |
| 76 | return p.row >= r.start_row && p.row < r.end_row && |
| 77 | p.col >= r.start_col && p.col < r.end_col; |
| 78 | } |
| 79 | #endif |
| 80 | |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 81 | /* move a rect */ |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 82 | // Move "rect" "row_delta" down and "col_delta" right. |
| 83 | // Does not check boundaries. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 84 | void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta); |
| 85 | |
| 86 | #if defined(DEFINE_INLINES) || USE_INLINE |
| 87 | INLINE void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta) |
| 88 | { |
| 89 | rect->start_row += row_delta; rect->end_row += row_delta; |
| 90 | rect->start_col += col_delta; rect->end_col += col_delta; |
| 91 | } |
| 92 | #endif |
| 93 | |
Bram Moolenaar | e5886cc | 2020-05-21 20:10:04 +0200 | [diff] [blame] | 94 | /** |
| 95 | * Bit-field describing the value of VTermColor.type |
| 96 | */ |
| 97 | typedef enum { |
| 98 | /** |
| 99 | * If the lower bit of `type` is not set, the colour is 24-bit RGB. |
| 100 | */ |
| 101 | VTERM_COLOR_RGB = 0x00, |
| 102 | |
| 103 | /** |
| 104 | * The colour is an index into a palette of 256 colours. |
| 105 | */ |
| 106 | VTERM_COLOR_INDEXED = 0x01, |
| 107 | |
| 108 | /** |
| 109 | * Mask that can be used to extract the RGB/Indexed bit. |
| 110 | */ |
| 111 | VTERM_COLOR_TYPE_MASK = 0x01, |
| 112 | |
| 113 | /** |
| 114 | * If set, indicates that this colour should be the default foreground |
| 115 | * color, i.e. there was no SGR request for another colour. When |
| 116 | * rendering this colour it is possible to ignore "idx" and just use a |
| 117 | * colour that is not in the palette. |
| 118 | */ |
| 119 | VTERM_COLOR_DEFAULT_FG = 0x02, |
| 120 | |
| 121 | /** |
| 122 | * If set, indicates that this colour should be the default background |
| 123 | * color, i.e. there was no SGR request for another colour. A common |
| 124 | * option when rendering this colour is to not render a background at |
| 125 | * all, for example by rendering the window transparently at this spot. |
| 126 | */ |
| 127 | VTERM_COLOR_DEFAULT_BG = 0x04, |
| 128 | |
| 129 | /** |
| 130 | * Mask that can be used to extract the default foreground/background bit. |
| 131 | */ |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 132 | VTERM_COLOR_DEFAULT_MASK = 0x06, |
| 133 | |
| 134 | /** |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 135 | * VIM: If set, indicates that the color is invalid. |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 136 | */ |
| 137 | VTERM_COLOR_INVALID = 0x08 |
Bram Moolenaar | e5886cc | 2020-05-21 20:10:04 +0200 | [diff] [blame] | 138 | } VTermColorType; |
| 139 | |
| 140 | /** |
| 141 | * Returns true if the VTERM_COLOR_RGB `type` flag is set, indicating that the |
| 142 | * given VTermColor instance is an indexed colour. |
| 143 | */ |
| 144 | #define VTERM_COLOR_IS_INDEXED(col) \ |
| 145 | (((col)->type & VTERM_COLOR_TYPE_MASK) == VTERM_COLOR_INDEXED) |
| 146 | |
| 147 | /** |
| 148 | * Returns true if the VTERM_COLOR_INDEXED `type` flag is set, indicating that |
| 149 | * the given VTermColor instance is an rgb colour. |
| 150 | */ |
| 151 | #define VTERM_COLOR_IS_RGB(col) \ |
| 152 | (((col)->type & VTERM_COLOR_TYPE_MASK) == VTERM_COLOR_RGB) |
| 153 | |
| 154 | /** |
| 155 | * Returns true if the VTERM_COLOR_DEFAULT_FG `type` flag is set, indicating |
| 156 | * that the given VTermColor instance corresponds to the default foreground |
| 157 | * color. |
| 158 | */ |
| 159 | #define VTERM_COLOR_IS_DEFAULT_FG(col) \ |
| 160 | (!!((col)->type & VTERM_COLOR_DEFAULT_FG)) |
| 161 | |
| 162 | /** |
| 163 | * Returns true if the VTERM_COLOR_DEFAULT_BG `type` flag is set, indicating |
| 164 | * that the given VTermColor instance corresponds to the default background |
| 165 | * color. |
| 166 | */ |
| 167 | #define VTERM_COLOR_IS_DEFAULT_BG(col) \ |
| 168 | (!!((col)->type & VTERM_COLOR_DEFAULT_BG)) |
Bram Moolenaar | 46359e1 | 2017-11-29 22:33:38 +0100 | [diff] [blame] | 169 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 170 | /** |
| 171 | * Returns true if the VTERM_COLOR_INVALID `type` flag is set, indicating |
| 172 | * that the given VTermColor instance is an invalid color. |
| 173 | */ |
| 174 | #define VTERM_COLOR_IS_INVALID(col) (!!((col)->type & VTERM_COLOR_INVALID)) |
| 175 | |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 176 | // VIM: this was a union, but that doesn't always work. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 177 | typedef struct { |
Bram Moolenaar | e5886cc | 2020-05-21 20:10:04 +0200 | [diff] [blame] | 178 | /** |
| 179 | * Tag indicating which member is actually valid. |
| 180 | * Please use the `VTERM_COLOR_IS_*` test macros to check whether a |
| 181 | * particular type flag is set. |
| 182 | */ |
| 183 | uint8_t type; |
| 184 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 185 | uint8_t red, green, blue; |
Bram Moolenaar | e5886cc | 2020-05-21 20:10:04 +0200 | [diff] [blame] | 186 | |
| 187 | uint8_t index; |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 188 | } VTermColor; |
| 189 | |
Bram Moolenaar | e5886cc | 2020-05-21 20:10:04 +0200 | [diff] [blame] | 190 | /** |
| 191 | * Constructs a new VTermColor instance representing the given RGB values. |
| 192 | */ |
| 193 | void vterm_color_rgb(VTermColor *col, uint8_t red, uint8_t green, uint8_t blue); |
| 194 | |
| 195 | /** |
| 196 | * Construct a new VTermColor instance representing an indexed color with the |
| 197 | * given index. |
| 198 | */ |
| 199 | void vterm_color_indexed(VTermColor *col, uint8_t idx); |
| 200 | |
| 201 | /** |
| 202 | * Compares two colours. Returns true if the colors are equal, false otherwise. |
| 203 | */ |
| 204 | int vterm_color_is_equal(const VTermColor *a, const VTermColor *b); |
| 205 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 206 | typedef enum { |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 207 | /* VTERM_VALUETYPE_NONE = 0 */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 208 | VTERM_VALUETYPE_BOOL = 1, |
| 209 | VTERM_VALUETYPE_INT, |
| 210 | VTERM_VALUETYPE_STRING, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 211 | VTERM_VALUETYPE_COLOR, |
| 212 | |
| 213 | VTERM_N_VALUETYPES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 214 | } VTermValueType; |
| 215 | |
Bram Moolenaar | be593bf | 2020-05-19 21:20:04 +0200 | [diff] [blame] | 216 | typedef struct { |
| 217 | const char *str; |
| 218 | size_t len : 30; |
| 219 | unsigned int initial : 1; |
| 220 | unsigned int final : 1; |
| 221 | } VTermStringFragment; |
| 222 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 223 | typedef union { |
| 224 | int boolean; |
| 225 | int number; |
Bram Moolenaar | be593bf | 2020-05-19 21:20:04 +0200 | [diff] [blame] | 226 | VTermStringFragment string; |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 227 | VTermColor color; |
| 228 | } VTermValue; |
| 229 | |
| 230 | typedef enum { |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 231 | /* VTERM_ATTR_NONE = 0 */ |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 232 | VTERM_ATTR_BOLD = 1, // bool: 1, 22 |
| 233 | VTERM_ATTR_UNDERLINE, // number: 4, 21, 24 |
| 234 | VTERM_ATTR_ITALIC, // bool: 3, 23 |
| 235 | VTERM_ATTR_BLINK, // bool: 5, 25 |
| 236 | VTERM_ATTR_REVERSE, // bool: 7, 27 |
Bram Moolenaar | d863728 | 2020-05-20 18:41:41 +0200 | [diff] [blame] | 237 | VTERM_ATTR_CONCEAL, // bool: 8, 28 |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 238 | VTERM_ATTR_STRIKE, // bool: 9, 29 |
| 239 | VTERM_ATTR_FONT, // number: 10-19 |
| 240 | VTERM_ATTR_FOREGROUND, // color: 30-39 90-97 |
| 241 | VTERM_ATTR_BACKGROUND, // color: 40-49 100-107 |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 242 | VTERM_ATTR_SMALL, // bool: 73, 74, 75 |
| 243 | VTERM_ATTR_BASELINE, // number: 73, 74, 75 |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 244 | |
| 245 | VTERM_N_ATTRS |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 246 | } VTermAttr; |
| 247 | |
| 248 | typedef enum { |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 249 | /* VTERM_PROP_NONE = 0 */ |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 250 | VTERM_PROP_CURSORVISIBLE = 1, // bool |
| 251 | VTERM_PROP_CURSORBLINK, // bool |
| 252 | VTERM_PROP_ALTSCREEN, // bool |
| 253 | VTERM_PROP_TITLE, // string |
| 254 | VTERM_PROP_ICONNAME, // string |
| 255 | VTERM_PROP_REVERSE, // bool |
| 256 | VTERM_PROP_CURSORSHAPE, // number |
| 257 | VTERM_PROP_MOUSE, // number |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 258 | VTERM_PROP_CURSORCOLOR, // VIM - string |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 259 | |
| 260 | VTERM_N_PROPS |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 261 | } VTermProp; |
| 262 | |
| 263 | enum { |
| 264 | VTERM_PROP_CURSORSHAPE_BLOCK = 1, |
| 265 | VTERM_PROP_CURSORSHAPE_UNDERLINE, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 266 | VTERM_PROP_CURSORSHAPE_BAR_LEFT, |
| 267 | |
| 268 | VTERM_N_PROP_CURSORSHAPES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | enum { |
| 272 | VTERM_PROP_MOUSE_NONE = 0, |
| 273 | VTERM_PROP_MOUSE_CLICK, |
| 274 | VTERM_PROP_MOUSE_DRAG, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 275 | VTERM_PROP_MOUSE_MOVE, |
| 276 | |
| 277 | VTERM_N_PROP_MOUSES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 278 | }; |
| 279 | |
Bram Moolenaar | 7da3415 | 2021-11-24 19:30:55 +0000 | [diff] [blame] | 280 | typedef enum { |
| 281 | VTERM_SELECTION_CLIPBOARD = (1<<0), |
| 282 | VTERM_SELECTION_PRIMARY = (1<<1), |
| 283 | VTERM_SELECTION_SECONDARY = (1<<2), |
| 284 | VTERM_SELECTION_SELECT = (1<<3), |
| 285 | VTERM_SELECTION_CUT0 = (1<<4), /* also CUT1 .. CUT7 by bitshifting */ |
| 286 | } VTermSelectionMask; |
| 287 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 288 | typedef struct { |
| 289 | const uint32_t *chars; |
| 290 | int width; |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 291 | unsigned int protected_cell:1; /* DECSCA-protected against DECSEL/DECSED */ |
| 292 | unsigned int dwl:1; /* DECDWL or DECDHL double-width line */ |
| 293 | unsigned int dhl:2; /* DECDHL double-height line (1=top 2=bottom) */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 294 | } VTermGlyphInfo; |
| 295 | |
| 296 | typedef struct { |
Bram Moolenaar | 88d68de | 2020-05-18 21:51:01 +0200 | [diff] [blame] | 297 | unsigned int doublewidth:1; /* DECDWL or DECDHL line */ |
| 298 | unsigned int doubleheight:2; /* DECDHL line (1=top 2=bottom) */ |
| 299 | unsigned int continuation:1; /* Line is a flow continuation of the previous */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 300 | } VTermLineInfo; |
| 301 | |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 302 | /* Copies of VTermState fields that the 'resize' callback might have reason to |
| 303 | * edit. 'resize' callback gets total control of these fields and may |
| 304 | * free-and-reallocate them if required. They will be copied back from the |
| 305 | * struct after the callback has returned. |
| 306 | */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 307 | typedef struct { |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 308 | VTermPos pos; /* current cursor position */ |
Bram Moolenaar | 501e777 | 2022-10-16 14:35:46 +0100 | [diff] [blame] | 309 | VTermLineInfo *lineinfos[2]; /* [1] may be NULL */ |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 310 | } VTermStateFields; |
| 311 | |
| 312 | typedef struct { |
| 313 | /* libvterm relies on this memory to be zeroed out before it is returned |
| 314 | * by the allocator. */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 315 | void *(*malloc)(size_t size, void *allocdata); |
| 316 | void (*free)(void *ptr, void *allocdata); |
| 317 | } VTermAllocatorFunctions; |
| 318 | |
Bram Moolenaar | 6fc3b59 | 2020-05-17 22:27:55 +0200 | [diff] [blame] | 319 | void vterm_check_version(int major, int minor); |
| 320 | |
Bram Moolenaar | 501e777 | 2022-10-16 14:35:46 +0100 | [diff] [blame] | 321 | struct VTermBuilder { |
| 322 | int ver; /* currently unused but reserved for some sort of ABI version flag */ |
| 323 | |
| 324 | int rows, cols; |
| 325 | |
| 326 | const VTermAllocatorFunctions *allocator; |
| 327 | void *allocdata; |
| 328 | |
| 329 | /* Override default sizes for various structures */ |
| 330 | size_t outbuffer_len; /* default: 4096 */ |
| 331 | size_t tmpbuffer_len; /* default: 4096 */ |
| 332 | }; |
| 333 | |
| 334 | VTerm *vterm_build(const struct VTermBuilder *builder); |
| 335 | |
| 336 | /* A convenient shortcut for default cases */ |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 337 | // Allocate and initialize a new terminal with default allocators. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 338 | VTerm *vterm_new(int rows, int cols); |
Bram Moolenaar | 501e777 | 2022-10-16 14:35:46 +0100 | [diff] [blame] | 339 | /* These shortcuts are generally discouraged in favour of just using vterm_build() */ |
| 340 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 341 | // Allocate and initialize a new terminal with specified allocators. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 342 | VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata); |
| 343 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 344 | // Free and cleanup a terminal and all its data. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 345 | void vterm_free(VTerm* vt); |
| 346 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 347 | // Get the current size of the terminal and store in "rowsp" and "colsp". |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 348 | void vterm_get_size(const VTerm *vt, int *rowsp, int *colsp); |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 349 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 350 | void vterm_set_size(VTerm *vt, int rows, int cols); |
| 351 | |
| 352 | int vterm_get_utf8(const VTerm *vt); |
| 353 | void vterm_set_utf8(VTerm *vt, int is_utf8); |
| 354 | |
| 355 | size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len); |
| 356 | |
Bram Moolenaar | 94d729c | 2020-05-17 21:50:16 +0200 | [diff] [blame] | 357 | /* Setting output callback will override the buffer logic */ |
| 358 | typedef void VTermOutputCallback(const char *s, size_t len, void *user); |
| 359 | void vterm_output_set_callback(VTerm *vt, VTermOutputCallback *func, void *user); |
| 360 | |
| 361 | /* These buffer functions only work if output callback is NOT set |
| 362 | * These are deprecated and will be removed in a later version */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 363 | size_t vterm_output_get_buffer_size(const VTerm *vt); |
| 364 | size_t vterm_output_get_buffer_current(const VTerm *vt); |
| 365 | size_t vterm_output_get_buffer_remaining(const VTerm *vt); |
| 366 | |
Bram Moolenaar | 94d729c | 2020-05-17 21:50:16 +0200 | [diff] [blame] | 367 | /* This too */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 368 | size_t vterm_output_read(VTerm *vt, char *buffer, size_t len); |
| 369 | |
Bram Moolenaar | 6a0299d | 2019-10-10 21:14:03 +0200 | [diff] [blame] | 370 | int vterm_is_modify_other_keys(VTerm *vt); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 371 | void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod); |
| 372 | void vterm_keyboard_key(VTerm *vt, VTermKey key, VTermModifier mod); |
| 373 | |
| 374 | void vterm_keyboard_start_paste(VTerm *vt); |
| 375 | void vterm_keyboard_end_paste(VTerm *vt); |
| 376 | |
| 377 | void vterm_mouse_move(VTerm *vt, int row, int col, VTermModifier mod); |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 378 | // "button" is 1 for left, 2 for middle, 3 for right. |
| 379 | // Button 4 is scroll wheel down, button 5 is scroll wheel up. |
Bram Moolenaar | b2a76ec | 2017-07-25 21:34:46 +0200 | [diff] [blame] | 380 | void vterm_mouse_button(VTerm *vt, int button, int pressed, VTermModifier mod); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 381 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 382 | // ------------ |
| 383 | // Parser layer |
| 384 | // ------------ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 385 | |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 386 | /* Flag to indicate non-final subparameters in a single CSI parameter. |
| 387 | * Consider |
| 388 | * CSI 1;2:3:4;5a |
| 389 | * 1 4 and 5 are final. |
| 390 | * 2 and 3 are non-final and will have this bit set |
| 391 | * |
| 392 | * Don't confuse this with the final byte of the CSI escape; 'a' in this case. |
| 393 | */ |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 394 | #define CSI_ARG_FLAG_MORE (1U<<31) |
| 395 | #define CSI_ARG_MASK (~(1U<<31)) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 396 | |
| 397 | #define CSI_ARG_HAS_MORE(a) ((a) & CSI_ARG_FLAG_MORE) |
| 398 | #define CSI_ARG(a) ((a) & CSI_ARG_MASK) |
| 399 | |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 400 | /* Can't use -1 to indicate a missing argument; use this instead */ |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 401 | // VIM: changed 31 to 30 to avoid an overflow warning |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 402 | #define CSI_ARG_MISSING ((1<<30)-1) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 403 | |
| 404 | #define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING) |
| 405 | #define CSI_ARG_OR(a,def) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a)) |
| 406 | #define CSI_ARG_COUNT(a) (CSI_ARG(a) == CSI_ARG_MISSING || CSI_ARG(a) == 0 ? 1 : CSI_ARG(a)) |
| 407 | |
| 408 | typedef struct { |
| 409 | int (*text)(const char *bytes, size_t len, void *user); |
| 410 | int (*control)(unsigned char control, void *user); |
| 411 | int (*escape)(const char *bytes, size_t len, void *user); |
| 412 | int (*csi)(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user); |
Bram Moolenaar | be593bf | 2020-05-19 21:20:04 +0200 | [diff] [blame] | 413 | int (*osc)(int command, VTermStringFragment frag, void *user); |
| 414 | int (*dcs)(const char *command, size_t commandlen, VTermStringFragment frag, void *user); |
Bram Moolenaar | 7da3415 | 2021-11-24 19:30:55 +0000 | [diff] [blame] | 415 | int (*apc)(VTermStringFragment frag, void *user); |
| 416 | int (*pm)(VTermStringFragment frag, void *user); |
| 417 | int (*sos)(VTermStringFragment frag, void *user); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 418 | int (*resize)(int rows, int cols, void *user); |
| 419 | } VTermParserCallbacks; |
| 420 | |
| 421 | void vterm_parser_set_callbacks(VTerm *vt, const VTermParserCallbacks *callbacks, void *user); |
| 422 | void *vterm_parser_get_cbdata(VTerm *vt); |
| 423 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 424 | // ----------- |
| 425 | // State layer |
| 426 | // ----------- |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 427 | |
| 428 | typedef struct { |
| 429 | int (*putglyph)(VTermGlyphInfo *info, VTermPos pos, void *user); |
| 430 | int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user); |
| 431 | int (*scrollrect)(VTermRect rect, int downward, int rightward, void *user); |
| 432 | int (*moverect)(VTermRect dest, VTermRect src, void *user); |
| 433 | int (*erase)(VTermRect rect, int selective, void *user); |
| 434 | int (*initpen)(void *user); |
| 435 | int (*setpenattr)(VTermAttr attr, VTermValue *val, void *user); |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 436 | // Callback for setting various properties. Must return 1 if the property |
| 437 | // was accepted, 0 otherwise. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 438 | int (*settermprop)(VTermProp prop, VTermValue *val, void *user); |
| 439 | int (*bell)(void *user); |
Bram Moolenaar | d098b82 | 2020-05-18 21:12:59 +0200 | [diff] [blame] | 440 | int (*resize)(int rows, int cols, VTermStateFields *fields, void *user); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 441 | int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user); |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 442 | int (*sb_clear)(void *user); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 443 | } VTermStateCallbacks; |
| 444 | |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 445 | // VIM: added |
Bram Moolenaar | c48369c | 2018-03-11 19:30:45 +0100 | [diff] [blame] | 446 | typedef struct { |
| 447 | VTermPos pos; |
| 448 | int buttons; |
| 449 | #define MOUSE_BUTTON_LEFT 0x01 |
| 450 | #define MOUSE_BUTTON_MIDDLE 0x02 |
| 451 | #define MOUSE_BUTTON_RIGHT 0x04 |
| 452 | int flags; |
| 453 | #define MOUSE_WANT_CLICK 0x01 |
| 454 | #define MOUSE_WANT_DRAG 0x02 |
| 455 | #define MOUSE_WANT_MOVE 0x04 |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 456 | // useful to add protocol? |
Bram Moolenaar | c48369c | 2018-03-11 19:30:45 +0100 | [diff] [blame] | 457 | } VTermMouseState; |
| 458 | |
Bram Moolenaar | d863728 | 2020-05-20 18:41:41 +0200 | [diff] [blame] | 459 | typedef struct { |
| 460 | int (*control)(unsigned char control, void *user); |
| 461 | int (*csi)(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user); |
| 462 | int (*osc)(int command, VTermStringFragment frag, void *user); |
| 463 | int (*dcs)(const char *command, size_t commandlen, VTermStringFragment frag, void *user); |
Bram Moolenaar | 7da3415 | 2021-11-24 19:30:55 +0000 | [diff] [blame] | 464 | int (*apc)(VTermStringFragment frag, void *user); |
| 465 | int (*pm)(VTermStringFragment frag, void *user); |
| 466 | int (*sos)(VTermStringFragment frag, void *user); |
Bram Moolenaar | d863728 | 2020-05-20 18:41:41 +0200 | [diff] [blame] | 467 | } VTermStateFallbacks; |
| 468 | |
Bram Moolenaar | 7da3415 | 2021-11-24 19:30:55 +0000 | [diff] [blame] | 469 | typedef struct { |
| 470 | int (*set)(VTermSelectionMask mask, VTermStringFragment frag, void *user); |
| 471 | int (*query)(VTermSelectionMask mask, void *user); |
| 472 | } VTermSelectionCallbacks; |
| 473 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 474 | VTermState *vterm_obtain_state(VTerm *vt); |
| 475 | |
| 476 | void vterm_state_set_callbacks(VTermState *state, const VTermStateCallbacks *callbacks, void *user); |
| 477 | void *vterm_state_get_cbdata(VTermState *state); |
| 478 | |
Bram Moolenaar | d863728 | 2020-05-20 18:41:41 +0200 | [diff] [blame] | 479 | void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermStateFallbacks *fallbacks, void *user); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 480 | void *vterm_state_get_unrecognised_fbdata(VTermState *state); |
| 481 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 482 | // Initialize the state. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 483 | void vterm_state_reset(VTermState *state, int hard); |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 484 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 485 | void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos); |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 486 | // VIM: added |
Bram Moolenaar | c48369c | 2018-03-11 19:30:45 +0100 | [diff] [blame] | 487 | void vterm_state_get_mousestate(const VTermState *state, VTermMouseState *mousestate); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 488 | void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg); |
| 489 | void vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col); |
| 490 | void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg); |
| 491 | void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col); |
| 492 | void vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright); |
| 493 | int vterm_state_get_penattr(const VTermState *state, VTermAttr attr, VTermValue *val); |
| 494 | int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val); |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 495 | void vterm_state_focus_in(VTermState *state); |
| 496 | void vterm_state_focus_out(VTermState *state); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 497 | const VTermLineInfo *vterm_state_get_lineinfo(const VTermState *state, int row); |
| 498 | |
Bram Moolenaar | e5886cc | 2020-05-21 20:10:04 +0200 | [diff] [blame] | 499 | /** |
| 500 | * Makes sure that the given color `col` is indeed an RGB colour. After this |
| 501 | * function returns, VTERM_COLOR_IS_RGB(col) will return true, while all other |
| 502 | * flags stored in `col->type` will have been reset. |
| 503 | * |
| 504 | * @param state is the VTermState instance from which the colour palette should |
| 505 | * be extracted. |
| 506 | * @param col is a pointer at the VTermColor instance that should be converted |
| 507 | * to an RGB colour. |
| 508 | */ |
| 509 | void vterm_state_convert_color_to_rgb(const VTermState *state, VTermColor *col); |
| 510 | |
Bram Moolenaar | 7da3415 | 2021-11-24 19:30:55 +0000 | [diff] [blame] | 511 | void vterm_state_set_selection_callbacks(VTermState *state, const VTermSelectionCallbacks *callbacks, void *user, |
| 512 | char *buffer, size_t buflen); |
| 513 | |
| 514 | void vterm_state_send_selection(VTermState *state, VTermSelectionMask mask, VTermStringFragment frag); |
| 515 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 516 | // ------------ |
| 517 | // Screen layer |
| 518 | // ------------ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 519 | |
| 520 | typedef struct { |
| 521 | unsigned int bold : 1; |
| 522 | unsigned int underline : 2; |
| 523 | unsigned int italic : 1; |
| 524 | unsigned int blink : 1; |
| 525 | unsigned int reverse : 1; |
Bram Moolenaar | d863728 | 2020-05-20 18:41:41 +0200 | [diff] [blame] | 526 | unsigned int conceal : 1; |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 527 | unsigned int strike : 1; |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 528 | unsigned int font : 4; /* 0 to 9 */ |
| 529 | unsigned int dwl : 1; /* On a DECDWL or DECDHL line */ |
| 530 | unsigned int dhl : 2; /* On a DECDHL line (1=top 2=bottom) */ |
Bram Moolenaar | e6a16e9 | 2022-10-17 14:51:36 +0100 | [diff] [blame] | 531 | unsigned int small : 1; |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 532 | unsigned int baseline : 2; |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 533 | } VTermScreenCellAttrs; |
| 534 | |
Bram Moolenaar | 6fc3b59 | 2020-05-17 22:27:55 +0200 | [diff] [blame] | 535 | enum { |
| 536 | VTERM_UNDERLINE_OFF, |
| 537 | VTERM_UNDERLINE_SINGLE, |
| 538 | VTERM_UNDERLINE_DOUBLE, |
| 539 | VTERM_UNDERLINE_CURLY, |
| 540 | }; |
| 541 | |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 542 | enum { |
| 543 | VTERM_BASELINE_NORMAL, |
| 544 | VTERM_BASELINE_RAISE, |
| 545 | VTERM_BASELINE_LOWER, |
| 546 | }; |
| 547 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 548 | typedef struct { |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 549 | uint32_t chars[VTERM_MAX_CHARS_PER_CELL]; |
| 550 | char width; |
| 551 | VTermScreenCellAttrs attrs; |
| 552 | VTermColor fg, bg; |
| 553 | } VTermScreenCell; |
| 554 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 555 | // All fields are optional, NULL when not used. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 556 | typedef struct { |
| 557 | int (*damage)(VTermRect rect, void *user); |
| 558 | int (*moverect)(VTermRect dest, VTermRect src, void *user); |
| 559 | int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user); |
| 560 | int (*settermprop)(VTermProp prop, VTermValue *val, void *user); |
| 561 | int (*bell)(void *user); |
| 562 | int (*resize)(int rows, int cols, void *user); |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 563 | // A line was pushed off the top of the window. |
| 564 | // "cells[cols]" contains the cells of that line. |
| 565 | // Return value is unused. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 566 | int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user); |
| 567 | int (*sb_popline)(int cols, VTermScreenCell *cells, void *user); |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 568 | int (*sb_clear)(void* user); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 569 | } VTermScreenCallbacks; |
| 570 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 571 | // Return the screen of the vterm. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 572 | VTermScreen *vterm_obtain_screen(VTerm *vt); |
| 573 | |
| 574 | /* |
| 575 | * Install screen callbacks. These are invoked when the screen contents is |
| 576 | * changed. "user" is passed into to the callback. |
| 577 | */ |
| 578 | void vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *user); |
| 579 | void *vterm_screen_get_cbdata(VTermScreen *screen); |
| 580 | |
Bram Moolenaar | d863728 | 2020-05-20 18:41:41 +0200 | [diff] [blame] | 581 | void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermStateFallbacks *fallbacks, void *user); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 582 | void *vterm_screen_get_unrecognised_fbdata(VTermScreen *screen); |
| 583 | |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 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 |
| 588 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 589 | // Enable support for using the alternate screen if "altscreen" is non-zero. |
| 590 | // Before that switching to the alternate screen won't work. |
| 591 | // Calling with "altscreen" zero has no effect. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 592 | void vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen); |
| 593 | |
| 594 | typedef enum { |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 595 | VTERM_DAMAGE_CELL, /* every cell */ |
| 596 | VTERM_DAMAGE_ROW, /* entire rows */ |
| 597 | VTERM_DAMAGE_SCREEN, /* entire screen */ |
| 598 | VTERM_DAMAGE_SCROLL, /* entire screen + scrollrect */ |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 599 | |
| 600 | VTERM_N_DAMAGES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 601 | } VTermDamageSize; |
| 602 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 603 | // Invoke the relevant callbacks to update the screen. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 604 | void vterm_screen_flush_damage(VTermScreen *screen); |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 605 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 606 | void vterm_screen_set_damage_merge(VTermScreen *screen, VTermDamageSize size); |
| 607 | |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 608 | /* |
| 609 | * Reset the screen. Also invokes vterm_state_reset(). |
| 610 | * Must be called before the terminal can be used. |
| 611 | */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 612 | void vterm_screen_reset(VTermScreen *screen, int hard); |
| 613 | |
Bram Moolenaar | 591cec8 | 2020-05-22 22:06:06 +0200 | [diff] [blame] | 614 | /* Neither of these functions NUL-terminate the buffer */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 615 | size_t vterm_screen_get_chars(const VTermScreen *screen, uint32_t *chars, size_t len, const VTermRect rect); |
| 616 | size_t vterm_screen_get_text(const VTermScreen *screen, char *str, size_t len, const VTermRect rect); |
| 617 | |
| 618 | typedef enum { |
| 619 | VTERM_ATTR_BOLD_MASK = 1 << 0, |
| 620 | VTERM_ATTR_UNDERLINE_MASK = 1 << 1, |
| 621 | VTERM_ATTR_ITALIC_MASK = 1 << 2, |
| 622 | VTERM_ATTR_BLINK_MASK = 1 << 3, |
| 623 | VTERM_ATTR_REVERSE_MASK = 1 << 4, |
| 624 | VTERM_ATTR_STRIKE_MASK = 1 << 5, |
| 625 | VTERM_ATTR_FONT_MASK = 1 << 6, |
| 626 | VTERM_ATTR_FOREGROUND_MASK = 1 << 7, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 627 | VTERM_ATTR_BACKGROUND_MASK = 1 << 8, |
Bram Moolenaar | d863728 | 2020-05-20 18:41:41 +0200 | [diff] [blame] | 628 | VTERM_ATTR_CONCEAL_MASK = 1 << 9, |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 629 | VTERM_ATTR_SMALL_MASK = 1 << 10, |
| 630 | VTERM_ATTR_BASELINE_MASK = 1 << 11, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 631 | |
Bram Moolenaar | 6a12d26 | 2022-10-16 19:26:52 +0100 | [diff] [blame] | 632 | VTERM_ALL_ATTRS_MASK = (1 << 12) - 1 |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 633 | } VTermAttrMask; |
| 634 | |
| 635 | int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs); |
| 636 | |
| 637 | int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell); |
| 638 | |
| 639 | int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos); |
| 640 | |
Bram Moolenaar | e5886cc | 2020-05-21 20:10:04 +0200 | [diff] [blame] | 641 | /** |
| 642 | * Same as vterm_state_convert_color_to_rgb(), but takes a `screen` instead of a `state` |
| 643 | * instance. |
| 644 | */ |
| 645 | void vterm_screen_convert_color_to_rgb(const VTermScreen *screen, VTermColor *col); |
| 646 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 647 | // --------- |
| 648 | // Utilities |
| 649 | // --------- |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 650 | |
| 651 | VTermValueType vterm_get_attr_type(VTermAttr attr); |
| 652 | VTermValueType vterm_get_prop_type(VTermProp prop); |
| 653 | |
| 654 | void vterm_scroll_rect(VTermRect rect, |
| 655 | int downward, |
| 656 | int rightward, |
| 657 | int (*moverect)(VTermRect src, VTermRect dest, void *user), |
| 658 | int (*eraserect)(VTermRect rect, int selective, void *user), |
| 659 | void *user); |
| 660 | |
| 661 | void vterm_copy_cells(VTermRect dest, |
| 662 | VTermRect src, |
| 663 | void (*copycell)(VTermPos dest, VTermPos src, void *user), |
| 664 | void *user); |
| 665 | |
| 666 | #ifdef __cplusplus |
| 667 | } |
| 668 | #endif |
| 669 | |
| 670 | #endif |