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 | b2a76ec | 2017-07-25 21:34:46 +0200 | [diff] [blame] | 15 | #define TRUE 1 |
| 16 | #define FALSE 0 |
| 17 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 18 | // from stdint.h |
Bram Moolenaar | 607985a | 2017-07-28 17:04:15 +0200 | [diff] [blame] | 19 | typedef unsigned char uint8_t; |
| 20 | typedef unsigned int uint32_t; |
| 21 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 22 | typedef struct VTerm VTerm; |
| 23 | typedef struct VTermState VTermState; |
| 24 | typedef struct VTermScreen VTermScreen; |
| 25 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 26 | // Specifies a screen point. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 27 | typedef struct { |
| 28 | int row; |
| 29 | int col; |
| 30 | } VTermPos; |
| 31 | |
| 32 | /* |
| 33 | * Some small utility functions; we can just keep these static here. |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | * Order points by on-screen flow order: |
| 38 | * Return < 0 if "a" is before "b" |
| 39 | * Return 0 if "a" and "b" are equal |
| 40 | * Return > 0 if "a" is after "b". |
| 41 | */ |
| 42 | int vterm_pos_cmp(VTermPos a, VTermPos b); |
| 43 | |
| 44 | #if defined(DEFINE_INLINES) || USE_INLINE |
| 45 | INLINE int vterm_pos_cmp(VTermPos a, VTermPos b) |
| 46 | { |
| 47 | return (a.row == b.row) ? a.col - b.col : a.row - b.row; |
| 48 | } |
| 49 | #endif |
| 50 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 51 | // Specifies a rectangular screen area. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 52 | typedef struct { |
| 53 | int start_row; |
| 54 | int end_row; |
| 55 | int start_col; |
| 56 | int end_col; |
| 57 | } VTermRect; |
| 58 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 59 | // Return true if the rect "r" contains the point "p". |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 60 | int vterm_rect_contains(VTermRect r, VTermPos p); |
| 61 | |
| 62 | #if defined(DEFINE_INLINES) || USE_INLINE |
| 63 | INLINE int vterm_rect_contains(VTermRect r, VTermPos p) |
| 64 | { |
| 65 | return p.row >= r.start_row && p.row < r.end_row && |
| 66 | p.col >= r.start_col && p.col < r.end_col; |
| 67 | } |
| 68 | #endif |
| 69 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 70 | // Move "rect" "row_delta" down and "col_delta" right. |
| 71 | // Does not check boundaries. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 72 | void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta); |
| 73 | |
| 74 | #if defined(DEFINE_INLINES) || USE_INLINE |
| 75 | INLINE void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta) |
| 76 | { |
| 77 | rect->start_row += row_delta; rect->end_row += row_delta; |
| 78 | rect->start_col += col_delta; rect->end_col += col_delta; |
| 79 | } |
| 80 | #endif |
| 81 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 82 | // The ansi_index is used for the lower 16 colors, which can be set to any |
| 83 | // color. |
| 84 | #define VTERM_ANSI_INDEX_DEFAULT 0 // color cleared |
Bram Moolenaar | 46359e1 | 2017-11-29 22:33:38 +0100 | [diff] [blame] | 85 | #define VTERM_ANSI_INDEX_MIN 1 |
| 86 | #define VTERM_ANSI_INDEX_MAX 16 |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 87 | #define VTERM_ANSI_INDEX_NONE 255 // non-ANSI color, use red/green/blue |
Bram Moolenaar | 46359e1 | 2017-11-29 22:33:38 +0100 | [diff] [blame] | 88 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 89 | typedef struct { |
| 90 | uint8_t red, green, blue; |
Bram Moolenaar | 46359e1 | 2017-11-29 22:33:38 +0100 | [diff] [blame] | 91 | uint8_t ansi_index; |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 92 | } VTermColor; |
| 93 | |
| 94 | typedef enum { |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 95 | // VTERM_VALUETYPE_NONE = 0 |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 96 | VTERM_VALUETYPE_BOOL = 1, |
| 97 | VTERM_VALUETYPE_INT, |
| 98 | VTERM_VALUETYPE_STRING, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 99 | VTERM_VALUETYPE_COLOR, |
| 100 | |
| 101 | VTERM_N_VALUETYPES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 102 | } VTermValueType; |
| 103 | |
| 104 | typedef union { |
| 105 | int boolean; |
| 106 | int number; |
| 107 | char *string; |
| 108 | VTermColor color; |
| 109 | } VTermValue; |
| 110 | |
| 111 | typedef enum { |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 112 | // VTERM_ATTR_NONE = 0 |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 113 | VTERM_ATTR_BOLD = 1, // bool: 1, 22 |
| 114 | VTERM_ATTR_UNDERLINE, // number: 4, 21, 24 |
| 115 | VTERM_ATTR_ITALIC, // bool: 3, 23 |
| 116 | VTERM_ATTR_BLINK, // bool: 5, 25 |
| 117 | VTERM_ATTR_REVERSE, // bool: 7, 27 |
| 118 | VTERM_ATTR_STRIKE, // bool: 9, 29 |
| 119 | VTERM_ATTR_FONT, // number: 10-19 |
| 120 | VTERM_ATTR_FOREGROUND, // color: 30-39 90-97 |
| 121 | VTERM_ATTR_BACKGROUND, // color: 40-49 100-107 |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 122 | |
| 123 | VTERM_N_ATTRS |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 124 | } VTermAttr; |
| 125 | |
| 126 | typedef enum { |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 127 | // VTERM_PROP_NONE = 0 |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 128 | VTERM_PROP_CURSORVISIBLE = 1, // bool |
| 129 | VTERM_PROP_CURSORBLINK, // bool |
| 130 | VTERM_PROP_ALTSCREEN, // bool |
| 131 | VTERM_PROP_TITLE, // string |
| 132 | VTERM_PROP_ICONNAME, // string |
| 133 | VTERM_PROP_REVERSE, // bool |
| 134 | VTERM_PROP_CURSORSHAPE, // number |
| 135 | VTERM_PROP_MOUSE, // number |
| 136 | VTERM_PROP_CURSORCOLOR, // string |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 137 | |
| 138 | VTERM_N_PROPS |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 139 | } VTermProp; |
| 140 | |
| 141 | enum { |
| 142 | VTERM_PROP_CURSORSHAPE_BLOCK = 1, |
| 143 | VTERM_PROP_CURSORSHAPE_UNDERLINE, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 144 | VTERM_PROP_CURSORSHAPE_BAR_LEFT, |
| 145 | |
| 146 | VTERM_N_PROP_CURSORSHAPES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | enum { |
| 150 | VTERM_PROP_MOUSE_NONE = 0, |
| 151 | VTERM_PROP_MOUSE_CLICK, |
| 152 | VTERM_PROP_MOUSE_DRAG, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 153 | VTERM_PROP_MOUSE_MOVE, |
| 154 | |
| 155 | VTERM_N_PROP_MOUSES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | typedef struct { |
| 159 | const uint32_t *chars; |
| 160 | int width; |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 161 | unsigned int protected_cell:1; // DECSCA-protected against DECSEL/DECSED |
| 162 | unsigned int dwl:1; // DECDWL or DECDHL double-width line |
| 163 | unsigned int dhl:2; // DECDHL double-height line (1=top 2=bottom) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 164 | } VTermGlyphInfo; |
| 165 | |
| 166 | typedef struct { |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 167 | unsigned int doublewidth:1; // DECDWL or DECDHL line |
| 168 | unsigned int doubleheight:2; // DECDHL line (1=top 2=bottom) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 169 | } VTermLineInfo; |
| 170 | |
| 171 | typedef struct { |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 172 | // libvterm relies on the allocated memory to be zeroed out before it is |
| 173 | // returned by the allocator. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 174 | void *(*malloc)(size_t size, void *allocdata); |
| 175 | void (*free)(void *ptr, void *allocdata); |
| 176 | } VTermAllocatorFunctions; |
| 177 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 178 | // Allocate and initialize a new terminal with default allocators. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 179 | VTerm *vterm_new(int rows, int cols); |
| 180 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 181 | // Allocate and initialize a new terminal with specified allocators. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 182 | VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata); |
| 183 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 184 | // Free and cleanup a terminal and all its data. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 185 | void vterm_free(VTerm* vt); |
| 186 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 187 | // 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] | 188 | void vterm_get_size(const VTerm *vt, int *rowsp, int *colsp); |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 189 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 190 | void vterm_set_size(VTerm *vt, int rows, int cols); |
| 191 | |
| 192 | int vterm_get_utf8(const VTerm *vt); |
| 193 | void vterm_set_utf8(VTerm *vt, int is_utf8); |
| 194 | |
| 195 | size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len); |
| 196 | |
| 197 | size_t vterm_output_get_buffer_size(const VTerm *vt); |
| 198 | size_t vterm_output_get_buffer_current(const VTerm *vt); |
| 199 | size_t vterm_output_get_buffer_remaining(const VTerm *vt); |
| 200 | |
| 201 | size_t vterm_output_read(VTerm *vt, char *buffer, size_t len); |
| 202 | |
| 203 | void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod); |
| 204 | void vterm_keyboard_key(VTerm *vt, VTermKey key, VTermModifier mod); |
| 205 | |
| 206 | void vterm_keyboard_start_paste(VTerm *vt); |
| 207 | void vterm_keyboard_end_paste(VTerm *vt); |
| 208 | |
| 209 | void vterm_mouse_move(VTerm *vt, int row, int col, VTermModifier mod); |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 210 | // "button" is 1 for left, 2 for middle, 3 for right. |
| 211 | // Button 4 is scroll wheel down, button 5 is scroll wheel up. |
Bram Moolenaar | b2a76ec | 2017-07-25 21:34:46 +0200 | [diff] [blame] | 212 | void vterm_mouse_button(VTerm *vt, int button, int pressed, VTermModifier mod); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 213 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 214 | // ------------ |
| 215 | // Parser layer |
| 216 | // ------------ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 217 | |
| 218 | /* Flag to indicate non-final subparameters in a single CSI parameter. |
| 219 | * Consider |
| 220 | * CSI 1;2:3:4;5a |
| 221 | * 1 4 and 5 are final. |
| 222 | * 2 and 3 are non-final and will have this bit set |
| 223 | * |
| 224 | * Don't confuse this with the final byte of the CSI escape; 'a' in this case. |
| 225 | */ |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 226 | #define CSI_ARG_FLAG_MORE (1U<<31) |
| 227 | #define CSI_ARG_MASK (~(1U<<31)) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 228 | |
| 229 | #define CSI_ARG_HAS_MORE(a) ((a) & CSI_ARG_FLAG_MORE) |
| 230 | #define CSI_ARG(a) ((a) & CSI_ARG_MASK) |
| 231 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 232 | // Can't use -1 to indicate a missing argument; use this instead |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 233 | #define CSI_ARG_MISSING ((1<<30)-1) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 234 | |
| 235 | #define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING) |
| 236 | #define CSI_ARG_OR(a,def) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a)) |
| 237 | #define CSI_ARG_COUNT(a) (CSI_ARG(a) == CSI_ARG_MISSING || CSI_ARG(a) == 0 ? 1 : CSI_ARG(a)) |
| 238 | |
| 239 | typedef struct { |
| 240 | int (*text)(const char *bytes, size_t len, void *user); |
| 241 | int (*control)(unsigned char control, void *user); |
| 242 | int (*escape)(const char *bytes, size_t len, void *user); |
| 243 | int (*csi)(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user); |
| 244 | int (*osc)(const char *command, size_t cmdlen, void *user); |
| 245 | int (*dcs)(const char *command, size_t cmdlen, void *user); |
| 246 | int (*resize)(int rows, int cols, void *user); |
| 247 | } VTermParserCallbacks; |
| 248 | |
| 249 | void vterm_parser_set_callbacks(VTerm *vt, const VTermParserCallbacks *callbacks, void *user); |
| 250 | void *vterm_parser_get_cbdata(VTerm *vt); |
| 251 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 252 | // ----------- |
| 253 | // State layer |
| 254 | // ----------- |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 255 | |
| 256 | typedef struct { |
| 257 | int (*putglyph)(VTermGlyphInfo *info, VTermPos pos, void *user); |
| 258 | int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user); |
| 259 | int (*scrollrect)(VTermRect rect, int downward, int rightward, void *user); |
| 260 | int (*moverect)(VTermRect dest, VTermRect src, void *user); |
| 261 | int (*erase)(VTermRect rect, int selective, void *user); |
| 262 | int (*initpen)(void *user); |
| 263 | int (*setpenattr)(VTermAttr attr, VTermValue *val, void *user); |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 264 | // Callback for setting various properties. Must return 1 if the property |
| 265 | // was accepted, 0 otherwise. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 266 | int (*settermprop)(VTermProp prop, VTermValue *val, void *user); |
| 267 | int (*bell)(void *user); |
| 268 | int (*resize)(int rows, int cols, VTermPos *delta, void *user); |
| 269 | int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user); |
| 270 | } VTermStateCallbacks; |
| 271 | |
Bram Moolenaar | c48369c | 2018-03-11 19:30:45 +0100 | [diff] [blame] | 272 | typedef struct { |
| 273 | VTermPos pos; |
| 274 | int buttons; |
| 275 | #define MOUSE_BUTTON_LEFT 0x01 |
| 276 | #define MOUSE_BUTTON_MIDDLE 0x02 |
| 277 | #define MOUSE_BUTTON_RIGHT 0x04 |
| 278 | int flags; |
| 279 | #define MOUSE_WANT_CLICK 0x01 |
| 280 | #define MOUSE_WANT_DRAG 0x02 |
| 281 | #define MOUSE_WANT_MOVE 0x04 |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 282 | // useful to add protocol? |
Bram Moolenaar | c48369c | 2018-03-11 19:30:45 +0100 | [diff] [blame] | 283 | } VTermMouseState; |
| 284 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 285 | VTermState *vterm_obtain_state(VTerm *vt); |
| 286 | |
| 287 | void vterm_state_set_callbacks(VTermState *state, const VTermStateCallbacks *callbacks, void *user); |
| 288 | void *vterm_state_get_cbdata(VTermState *state); |
| 289 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 290 | // Only invokes control, csi, osc, dcs |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 291 | void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermParserCallbacks *fallbacks, void *user); |
| 292 | void *vterm_state_get_unrecognised_fbdata(VTermState *state); |
| 293 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 294 | // Initialize the state. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 295 | void vterm_state_reset(VTermState *state, int hard); |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 296 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 297 | void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos); |
Bram Moolenaar | c48369c | 2018-03-11 19:30:45 +0100 | [diff] [blame] | 298 | void vterm_state_get_mousestate(const VTermState *state, VTermMouseState *mousestate); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 299 | void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg); |
| 300 | void vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col); |
| 301 | void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg); |
| 302 | void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col); |
| 303 | void vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright); |
| 304 | int vterm_state_get_penattr(const VTermState *state, VTermAttr attr, VTermValue *val); |
| 305 | int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val); |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 306 | void vterm_state_focus_in(VTermState *state); |
| 307 | void vterm_state_focus_out(VTermState *state); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 308 | const VTermLineInfo *vterm_state_get_lineinfo(const VTermState *state, int row); |
| 309 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 310 | // ------------ |
| 311 | // Screen layer |
| 312 | // ------------ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 313 | |
| 314 | typedef struct { |
| 315 | unsigned int bold : 1; |
| 316 | unsigned int underline : 2; |
| 317 | unsigned int italic : 1; |
| 318 | unsigned int blink : 1; |
| 319 | unsigned int reverse : 1; |
| 320 | unsigned int strike : 1; |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 321 | unsigned int font : 4; // 0 to 9 |
| 322 | unsigned int dwl : 1; // On a DECDWL or DECDHL line |
| 323 | unsigned int dhl : 2; // On a DECDHL line (1=top 2=bottom) |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 324 | } VTermScreenCellAttrs; |
| 325 | |
| 326 | typedef struct { |
| 327 | #define VTERM_MAX_CHARS_PER_CELL 6 |
| 328 | uint32_t chars[VTERM_MAX_CHARS_PER_CELL]; |
| 329 | char width; |
| 330 | VTermScreenCellAttrs attrs; |
| 331 | VTermColor fg, bg; |
| 332 | } VTermScreenCell; |
| 333 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 334 | // All fields are optional, NULL when not used. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 335 | typedef struct { |
| 336 | int (*damage)(VTermRect rect, void *user); |
| 337 | int (*moverect)(VTermRect dest, VTermRect src, void *user); |
| 338 | int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user); |
| 339 | int (*settermprop)(VTermProp prop, VTermValue *val, void *user); |
| 340 | int (*bell)(void *user); |
| 341 | int (*resize)(int rows, int cols, void *user); |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 342 | // A line was pushed off the top of the window. |
| 343 | // "cells[cols]" contains the cells of that line. |
| 344 | // Return value is unused. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 345 | int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user); |
| 346 | int (*sb_popline)(int cols, VTermScreenCell *cells, void *user); |
| 347 | } VTermScreenCallbacks; |
| 348 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 349 | // Return the screen of the vterm. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 350 | VTermScreen *vterm_obtain_screen(VTerm *vt); |
| 351 | |
| 352 | /* |
| 353 | * Install screen callbacks. These are invoked when the screen contents is |
| 354 | * changed. "user" is passed into to the callback. |
| 355 | */ |
| 356 | void vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *user); |
| 357 | void *vterm_screen_get_cbdata(VTermScreen *screen); |
| 358 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 359 | /* Only invokes control, csi, osc, dcs */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 360 | void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermParserCallbacks *fallbacks, void *user); |
| 361 | void *vterm_screen_get_unrecognised_fbdata(VTermScreen *screen); |
| 362 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 363 | // Enable support for using the alternate screen if "altscreen" is non-zero. |
| 364 | // Before that switching to the alternate screen won't work. |
| 365 | // Calling with "altscreen" zero has no effect. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 366 | void vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen); |
| 367 | |
| 368 | typedef enum { |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 369 | VTERM_DAMAGE_CELL, // every cell |
| 370 | VTERM_DAMAGE_ROW, // entire rows |
| 371 | VTERM_DAMAGE_SCREEN, // entire screen |
| 372 | VTERM_DAMAGE_SCROLL, // entire screen + scrollrect |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 373 | |
| 374 | VTERM_N_DAMAGES |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 375 | } VTermDamageSize; |
| 376 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 377 | // Invoke the relevant callbacks to update the screen. |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 378 | void vterm_screen_flush_damage(VTermScreen *screen); |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 379 | |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 380 | void vterm_screen_set_damage_merge(VTermScreen *screen, VTermDamageSize size); |
| 381 | |
Bram Moolenaar | 9cc5f75 | 2017-07-23 22:07:27 +0200 | [diff] [blame] | 382 | /* |
| 383 | * Reset the screen. Also invokes vterm_state_reset(). |
| 384 | * Must be called before the terminal can be used. |
| 385 | */ |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 386 | void vterm_screen_reset(VTermScreen *screen, int hard); |
| 387 | |
Bram Moolenaar | db1085a | 2019-08-18 20:41:38 +0200 | [diff] [blame] | 388 | // Neither of these functions NUL-terminate the buffer |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 389 | size_t vterm_screen_get_chars(const VTermScreen *screen, uint32_t *chars, size_t len, const VTermRect rect); |
| 390 | size_t vterm_screen_get_text(const VTermScreen *screen, char *str, size_t len, const VTermRect rect); |
| 391 | |
| 392 | typedef enum { |
| 393 | VTERM_ATTR_BOLD_MASK = 1 << 0, |
| 394 | VTERM_ATTR_UNDERLINE_MASK = 1 << 1, |
| 395 | VTERM_ATTR_ITALIC_MASK = 1 << 2, |
| 396 | VTERM_ATTR_BLINK_MASK = 1 << 3, |
| 397 | VTERM_ATTR_REVERSE_MASK = 1 << 4, |
| 398 | VTERM_ATTR_STRIKE_MASK = 1 << 5, |
| 399 | VTERM_ATTR_FONT_MASK = 1 << 6, |
| 400 | VTERM_ATTR_FOREGROUND_MASK = 1 << 7, |
Bram Moolenaar | b5b49a3 | 2018-03-25 16:20:37 +0200 | [diff] [blame] | 401 | VTERM_ATTR_BACKGROUND_MASK = 1 << 8, |
| 402 | |
| 403 | VTERM_ALL_ATTRS_MASK = (1 << 9) - 1 |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 404 | } VTermAttrMask; |
| 405 | |
| 406 | int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs); |
| 407 | |
| 408 | int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell); |
| 409 | |
| 410 | int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos); |
| 411 | |
Bram Moolenaar | b691de0 | 2018-04-24 18:39:14 +0200 | [diff] [blame] | 412 | // --------- |
| 413 | // Utilities |
| 414 | // --------- |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 415 | |
| 416 | VTermValueType vterm_get_attr_type(VTermAttr attr); |
| 417 | VTermValueType vterm_get_prop_type(VTermProp prop); |
| 418 | |
| 419 | void vterm_scroll_rect(VTermRect rect, |
| 420 | int downward, |
| 421 | int rightward, |
| 422 | int (*moverect)(VTermRect src, VTermRect dest, void *user), |
| 423 | int (*eraserect)(VTermRect rect, int selective, void *user), |
| 424 | void *user); |
| 425 | |
| 426 | void vterm_copy_cells(VTermRect dest, |
| 427 | VTermRect src, |
| 428 | void (*copycell)(VTermPos dest, VTermPos src, void *user), |
| 429 | void *user); |
| 430 | |
| 431 | #ifdef __cplusplus |
| 432 | } |
| 433 | #endif |
| 434 | |
| 435 | #endif |