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