blob: ea8f8cd106d80710bb09322ff75fc983ce19b34e [file] [log] [blame]
Bram Moolenaare4f25e42017-07-07 11:54:15 +02001/*
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
8extern "C" {
9#endif
10
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011#include <stdlib.h>
Bram Moolenaare4f25e42017-07-07 11:54:15 +020012
13#include "vterm_keycodes.h"
14
Bram Moolenaarb2a76ec2017-07-25 21:34:46 +020015#define TRUE 1
16#define FALSE 0
17
Bram Moolenaardb1085a2019-08-18 20:41:38 +020018// from stdint.h
Bram Moolenaar607985a2017-07-28 17:04:15 +020019typedef unsigned char uint8_t;
20typedef unsigned int uint32_t;
21
Bram Moolenaar6fc3b592020-05-17 22:27:55 +020022#define VTERM_VERSION_MAJOR 0
23#define VTERM_VERSION_MINOR 1
24
25#define VTERM_CHECK_VERSION \
26 vterm_check_version(VTERM_VERSION_MAJOR, VTERM_VERSION_MINOR)
27
Bram Moolenaare4f25e42017-07-07 11:54:15 +020028typedef struct VTerm VTerm;
29typedef struct VTermState VTermState;
30typedef struct VTermScreen VTermScreen;
31
Bram Moolenaardb1085a2019-08-18 20:41:38 +020032// Specifies a screen point.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020033typedef struct {
34 int row;
35 int col;
36} VTermPos;
37
38/*
39 * Some small utility functions; we can just keep these static here.
40 */
41
42/*
43 * Order points by on-screen flow order:
44 * Return < 0 if "a" is before "b"
45 * Return 0 if "a" and "b" are equal
46 * Return > 0 if "a" is after "b".
47 */
48int vterm_pos_cmp(VTermPos a, VTermPos b);
49
50#if defined(DEFINE_INLINES) || USE_INLINE
51INLINE int vterm_pos_cmp(VTermPos a, VTermPos b)
52{
53 return (a.row == b.row) ? a.col - b.col : a.row - b.row;
54}
55#endif
56
Bram Moolenaardb1085a2019-08-18 20:41:38 +020057// Specifies a rectangular screen area.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020058typedef struct {
59 int start_row;
60 int end_row;
61 int start_col;
62 int end_col;
63} VTermRect;
64
Bram Moolenaardb1085a2019-08-18 20:41:38 +020065// Return true if the rect "r" contains the point "p".
Bram Moolenaare4f25e42017-07-07 11:54:15 +020066int vterm_rect_contains(VTermRect r, VTermPos p);
67
68#if defined(DEFINE_INLINES) || USE_INLINE
69INLINE int vterm_rect_contains(VTermRect r, VTermPos p)
70{
71 return p.row >= r.start_row && p.row < r.end_row &&
72 p.col >= r.start_col && p.col < r.end_col;
73}
74#endif
75
Bram Moolenaardb1085a2019-08-18 20:41:38 +020076// Move "rect" "row_delta" down and "col_delta" right.
77// Does not check boundaries.
Bram Moolenaare4f25e42017-07-07 11:54:15 +020078void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta);
79
80#if defined(DEFINE_INLINES) || USE_INLINE
81INLINE void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta)
82{
83 rect->start_row += row_delta; rect->end_row += row_delta;
84 rect->start_col += col_delta; rect->end_col += col_delta;
85}
86#endif
87
Bram Moolenaardb1085a2019-08-18 20:41:38 +020088// The ansi_index is used for the lower 16 colors, which can be set to any
89// color.
90#define VTERM_ANSI_INDEX_DEFAULT 0 // color cleared
Bram Moolenaar46359e12017-11-29 22:33:38 +010091#define VTERM_ANSI_INDEX_MIN 1
92#define VTERM_ANSI_INDEX_MAX 16
Bram Moolenaardb1085a2019-08-18 20:41:38 +020093#define VTERM_ANSI_INDEX_NONE 255 // non-ANSI color, use red/green/blue
Bram Moolenaar46359e12017-11-29 22:33:38 +010094
Bram Moolenaare4f25e42017-07-07 11:54:15 +020095typedef struct {
96 uint8_t red, green, blue;
Bram Moolenaar46359e12017-11-29 22:33:38 +010097 uint8_t ansi_index;
Bram Moolenaare4f25e42017-07-07 11:54:15 +020098} VTermColor;
99
100typedef enum {
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200101 // VTERM_VALUETYPE_NONE = 0
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200102 VTERM_VALUETYPE_BOOL = 1,
103 VTERM_VALUETYPE_INT,
104 VTERM_VALUETYPE_STRING,
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200105 VTERM_VALUETYPE_COLOR,
106
107 VTERM_N_VALUETYPES
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200108} VTermValueType;
109
110typedef union {
111 int boolean;
112 int number;
113 char *string;
114 VTermColor color;
115} VTermValue;
116
117typedef enum {
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200118 // VTERM_ATTR_NONE = 0
Bram Moolenaarb691de02018-04-24 18:39:14 +0200119 VTERM_ATTR_BOLD = 1, // bool: 1, 22
120 VTERM_ATTR_UNDERLINE, // number: 4, 21, 24
121 VTERM_ATTR_ITALIC, // bool: 3, 23
122 VTERM_ATTR_BLINK, // bool: 5, 25
123 VTERM_ATTR_REVERSE, // bool: 7, 27
124 VTERM_ATTR_STRIKE, // bool: 9, 29
125 VTERM_ATTR_FONT, // number: 10-19
126 VTERM_ATTR_FOREGROUND, // color: 30-39 90-97
127 VTERM_ATTR_BACKGROUND, // color: 40-49 100-107
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200128
129 VTERM_N_ATTRS
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200130} VTermAttr;
131
132typedef enum {
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200133 // VTERM_PROP_NONE = 0
Bram Moolenaarb691de02018-04-24 18:39:14 +0200134 VTERM_PROP_CURSORVISIBLE = 1, // bool
135 VTERM_PROP_CURSORBLINK, // bool
136 VTERM_PROP_ALTSCREEN, // bool
137 VTERM_PROP_TITLE, // string
138 VTERM_PROP_ICONNAME, // string
139 VTERM_PROP_REVERSE, // bool
140 VTERM_PROP_CURSORSHAPE, // number
141 VTERM_PROP_MOUSE, // number
142 VTERM_PROP_CURSORCOLOR, // string
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200143
144 VTERM_N_PROPS
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200145} VTermProp;
146
147enum {
148 VTERM_PROP_CURSORSHAPE_BLOCK = 1,
149 VTERM_PROP_CURSORSHAPE_UNDERLINE,
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200150 VTERM_PROP_CURSORSHAPE_BAR_LEFT,
151
152 VTERM_N_PROP_CURSORSHAPES
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200153};
154
155enum {
156 VTERM_PROP_MOUSE_NONE = 0,
157 VTERM_PROP_MOUSE_CLICK,
158 VTERM_PROP_MOUSE_DRAG,
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200159 VTERM_PROP_MOUSE_MOVE,
160
161 VTERM_N_PROP_MOUSES
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200162};
163
164typedef struct {
165 const uint32_t *chars;
166 int width;
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200167 unsigned int protected_cell:1; // DECSCA-protected against DECSEL/DECSED
168 unsigned int dwl:1; // DECDWL or DECDHL double-width line
169 unsigned int dhl:2; // DECDHL double-height line (1=top 2=bottom)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200170} VTermGlyphInfo;
171
172typedef struct {
Bram Moolenaar88d68de2020-05-18 21:51:01 +0200173 unsigned int doublewidth:1; /* DECDWL or DECDHL line */
174 unsigned int doubleheight:2; /* DECDHL line (1=top 2=bottom) */
175 unsigned int continuation:1; /* Line is a flow continuation of the previous */
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200176} VTermLineInfo;
177
178typedef struct {
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200179 // libvterm relies on the allocated memory to be zeroed out before it is
180 // returned by the allocator.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200181 void *(*malloc)(size_t size, void *allocdata);
182 void (*free)(void *ptr, void *allocdata);
183} VTermAllocatorFunctions;
184
Bram Moolenaar6fc3b592020-05-17 22:27:55 +0200185void vterm_check_version(int major, int minor);
186
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200187// Allocate and initialize a new terminal with default allocators.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200188VTerm *vterm_new(int rows, int cols);
189
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200190// Allocate and initialize a new terminal with specified allocators.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200191VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata);
192
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200193// Free and cleanup a terminal and all its data.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200194void vterm_free(VTerm* vt);
195
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200196// Get the current size of the terminal and store in "rowsp" and "colsp".
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200197void vterm_get_size(const VTerm *vt, int *rowsp, int *colsp);
Bram Moolenaar9cc5f752017-07-23 22:07:27 +0200198
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200199void vterm_set_size(VTerm *vt, int rows, int cols);
200
201int vterm_get_utf8(const VTerm *vt);
202void vterm_set_utf8(VTerm *vt, int is_utf8);
203
204size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len);
205
Bram Moolenaar94d729c2020-05-17 21:50:16 +0200206/* Setting output callback will override the buffer logic */
207typedef void VTermOutputCallback(const char *s, size_t len, void *user);
208void vterm_output_set_callback(VTerm *vt, VTermOutputCallback *func, void *user);
209
210/* These buffer functions only work if output callback is NOT set
211 * These are deprecated and will be removed in a later version */
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200212size_t vterm_output_get_buffer_size(const VTerm *vt);
213size_t vterm_output_get_buffer_current(const VTerm *vt);
214size_t vterm_output_get_buffer_remaining(const VTerm *vt);
215
Bram Moolenaar94d729c2020-05-17 21:50:16 +0200216/* This too */
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200217size_t vterm_output_read(VTerm *vt, char *buffer, size_t len);
218
Bram Moolenaar6a0299d2019-10-10 21:14:03 +0200219int vterm_is_modify_other_keys(VTerm *vt);
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200220void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod);
221void vterm_keyboard_key(VTerm *vt, VTermKey key, VTermModifier mod);
222
223void vterm_keyboard_start_paste(VTerm *vt);
224void vterm_keyboard_end_paste(VTerm *vt);
225
226void vterm_mouse_move(VTerm *vt, int row, int col, VTermModifier mod);
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200227// "button" is 1 for left, 2 for middle, 3 for right.
228// Button 4 is scroll wheel down, button 5 is scroll wheel up.
Bram Moolenaarb2a76ec2017-07-25 21:34:46 +0200229void vterm_mouse_button(VTerm *vt, int button, int pressed, VTermModifier mod);
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200230
Bram Moolenaarb691de02018-04-24 18:39:14 +0200231// ------------
232// Parser layer
233// ------------
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200234
Bram Moolenaar707d2262019-12-04 22:16:54 +0100235// Flag to indicate non-final subparameters in a single CSI parameter.
236// Consider
237// CSI 1;2:3:4;5a
238// 1 4 and 5 are final.
239// 2 and 3 are non-final and will have this bit set
240//
241// Don't confuse this with the final byte of the CSI escape; 'a' in this case.
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200242#define CSI_ARG_FLAG_MORE (1U<<31)
243#define CSI_ARG_MASK (~(1U<<31))
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200244
245#define CSI_ARG_HAS_MORE(a) ((a) & CSI_ARG_FLAG_MORE)
246#define CSI_ARG(a) ((a) & CSI_ARG_MASK)
247
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200248// Can't use -1 to indicate a missing argument; use this instead
Bram Moolenaar9cc5f752017-07-23 22:07:27 +0200249#define CSI_ARG_MISSING ((1<<30)-1)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200250
251#define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING)
252#define CSI_ARG_OR(a,def) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a))
253#define CSI_ARG_COUNT(a) (CSI_ARG(a) == CSI_ARG_MISSING || CSI_ARG(a) == 0 ? 1 : CSI_ARG(a))
254
255typedef struct {
256 int (*text)(const char *bytes, size_t len, void *user);
257 int (*control)(unsigned char control, void *user);
258 int (*escape)(const char *bytes, size_t len, void *user);
259 int (*csi)(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user);
260 int (*osc)(const char *command, size_t cmdlen, void *user);
261 int (*dcs)(const char *command, size_t cmdlen, void *user);
262 int (*resize)(int rows, int cols, void *user);
263} VTermParserCallbacks;
264
265void vterm_parser_set_callbacks(VTerm *vt, const VTermParserCallbacks *callbacks, void *user);
266void *vterm_parser_get_cbdata(VTerm *vt);
267
Bram Moolenaarb691de02018-04-24 18:39:14 +0200268// -----------
269// State layer
270// -----------
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200271
Bram Moolenaard098b822020-05-18 21:12:59 +0200272/* Copies of VTermState fields that the 'resize' callback might have reason to
273 * edit. 'resize' callback gets total control of these fields and may
274 * free-and-reallocate them if required. They will be copied back from the
275 * struct after the callback has returned.
276 */
277typedef struct {
278 VTermPos pos; /* current cursor position */
279} VTermStateFields;
280
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200281typedef struct {
282 int (*putglyph)(VTermGlyphInfo *info, VTermPos pos, void *user);
283 int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user);
284 int (*scrollrect)(VTermRect rect, int downward, int rightward, void *user);
285 int (*moverect)(VTermRect dest, VTermRect src, void *user);
286 int (*erase)(VTermRect rect, int selective, void *user);
287 int (*initpen)(void *user);
288 int (*setpenattr)(VTermAttr attr, VTermValue *val, void *user);
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200289 // Callback for setting various properties. Must return 1 if the property
290 // was accepted, 0 otherwise.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200291 int (*settermprop)(VTermProp prop, VTermValue *val, void *user);
292 int (*bell)(void *user);
Bram Moolenaard098b822020-05-18 21:12:59 +0200293 int (*resize)(int rows, int cols, VTermStateFields *fields, void *user);
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200294 int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user);
295} VTermStateCallbacks;
296
Bram Moolenaarc48369c2018-03-11 19:30:45 +0100297typedef struct {
298 VTermPos pos;
299 int buttons;
300#define MOUSE_BUTTON_LEFT 0x01
301#define MOUSE_BUTTON_MIDDLE 0x02
302#define MOUSE_BUTTON_RIGHT 0x04
303 int flags;
304#define MOUSE_WANT_CLICK 0x01
305#define MOUSE_WANT_DRAG 0x02
306#define MOUSE_WANT_MOVE 0x04
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200307 // useful to add protocol?
Bram Moolenaarc48369c2018-03-11 19:30:45 +0100308} VTermMouseState;
309
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200310VTermState *vterm_obtain_state(VTerm *vt);
311
312void vterm_state_set_callbacks(VTermState *state, const VTermStateCallbacks *callbacks, void *user);
313void *vterm_state_get_cbdata(VTermState *state);
314
Bram Moolenaarb691de02018-04-24 18:39:14 +0200315// Only invokes control, csi, osc, dcs
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200316void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermParserCallbacks *fallbacks, void *user);
317void *vterm_state_get_unrecognised_fbdata(VTermState *state);
318
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200319// Initialize the state.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200320void vterm_state_reset(VTermState *state, int hard);
Bram Moolenaar9cc5f752017-07-23 22:07:27 +0200321
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200322void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos);
Bram Moolenaarc48369c2018-03-11 19:30:45 +0100323void vterm_state_get_mousestate(const VTermState *state, VTermMouseState *mousestate);
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200324void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg);
325void vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col);
326void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg);
327void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col);
328void vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright);
329int vterm_state_get_penattr(const VTermState *state, VTermAttr attr, VTermValue *val);
330int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val);
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200331void vterm_state_focus_in(VTermState *state);
332void vterm_state_focus_out(VTermState *state);
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200333const VTermLineInfo *vterm_state_get_lineinfo(const VTermState *state, int row);
334
Bram Moolenaarb691de02018-04-24 18:39:14 +0200335// ------------
336// Screen layer
337// ------------
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200338
339typedef struct {
340 unsigned int bold : 1;
341 unsigned int underline : 2;
342 unsigned int italic : 1;
343 unsigned int blink : 1;
344 unsigned int reverse : 1;
345 unsigned int strike : 1;
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200346 unsigned int font : 4; // 0 to 9
347 unsigned int dwl : 1; // On a DECDWL or DECDHL line
348 unsigned int dhl : 2; // On a DECDHL line (1=top 2=bottom)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200349} VTermScreenCellAttrs;
350
Bram Moolenaar6fc3b592020-05-17 22:27:55 +0200351enum {
352 VTERM_UNDERLINE_OFF,
353 VTERM_UNDERLINE_SINGLE,
354 VTERM_UNDERLINE_DOUBLE,
355 VTERM_UNDERLINE_CURLY,
356};
357
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200358typedef struct {
359#define VTERM_MAX_CHARS_PER_CELL 6
360 uint32_t chars[VTERM_MAX_CHARS_PER_CELL];
361 char width;
362 VTermScreenCellAttrs attrs;
363 VTermColor fg, bg;
364} VTermScreenCell;
365
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200366// All fields are optional, NULL when not used.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200367typedef struct {
368 int (*damage)(VTermRect rect, void *user);
369 int (*moverect)(VTermRect dest, VTermRect src, void *user);
370 int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user);
371 int (*settermprop)(VTermProp prop, VTermValue *val, void *user);
372 int (*bell)(void *user);
373 int (*resize)(int rows, int cols, void *user);
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200374 // A line was pushed off the top of the window.
375 // "cells[cols]" contains the cells of that line.
376 // Return value is unused.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200377 int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user);
378 int (*sb_popline)(int cols, VTermScreenCell *cells, void *user);
379} VTermScreenCallbacks;
380
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200381// Return the screen of the vterm.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200382VTermScreen *vterm_obtain_screen(VTerm *vt);
383
384/*
385 * Install screen callbacks. These are invoked when the screen contents is
386 * changed. "user" is passed into to the callback.
387 */
388void vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *user);
389void *vterm_screen_get_cbdata(VTermScreen *screen);
390
Bram Moolenaar707d2262019-12-04 22:16:54 +0100391// Only invokes control, csi, osc, dcs
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200392void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermParserCallbacks *fallbacks, void *user);
393void *vterm_screen_get_unrecognised_fbdata(VTermScreen *screen);
394
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200395// Enable support for using the alternate screen if "altscreen" is non-zero.
396// Before that switching to the alternate screen won't work.
397// Calling with "altscreen" zero has no effect.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200398void vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen);
399
400typedef enum {
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200401 VTERM_DAMAGE_CELL, // every cell
402 VTERM_DAMAGE_ROW, // entire rows
403 VTERM_DAMAGE_SCREEN, // entire screen
404 VTERM_DAMAGE_SCROLL, // entire screen + scrollrect
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200405
406 VTERM_N_DAMAGES
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200407} VTermDamageSize;
408
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200409// Invoke the relevant callbacks to update the screen.
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200410void vterm_screen_flush_damage(VTermScreen *screen);
Bram Moolenaar9cc5f752017-07-23 22:07:27 +0200411
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200412void vterm_screen_set_damage_merge(VTermScreen *screen, VTermDamageSize size);
413
Bram Moolenaar9cc5f752017-07-23 22:07:27 +0200414/*
415 * Reset the screen. Also invokes vterm_state_reset().
416 * Must be called before the terminal can be used.
417 */
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200418void vterm_screen_reset(VTermScreen *screen, int hard);
419
Bram Moolenaardb1085a2019-08-18 20:41:38 +0200420// Neither of these functions NUL-terminate the buffer
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200421size_t vterm_screen_get_chars(const VTermScreen *screen, uint32_t *chars, size_t len, const VTermRect rect);
422size_t vterm_screen_get_text(const VTermScreen *screen, char *str, size_t len, const VTermRect rect);
423
424typedef enum {
425 VTERM_ATTR_BOLD_MASK = 1 << 0,
426 VTERM_ATTR_UNDERLINE_MASK = 1 << 1,
427 VTERM_ATTR_ITALIC_MASK = 1 << 2,
428 VTERM_ATTR_BLINK_MASK = 1 << 3,
429 VTERM_ATTR_REVERSE_MASK = 1 << 4,
430 VTERM_ATTR_STRIKE_MASK = 1 << 5,
431 VTERM_ATTR_FONT_MASK = 1 << 6,
432 VTERM_ATTR_FOREGROUND_MASK = 1 << 7,
Bram Moolenaarb5b49a32018-03-25 16:20:37 +0200433 VTERM_ATTR_BACKGROUND_MASK = 1 << 8,
434
435 VTERM_ALL_ATTRS_MASK = (1 << 9) - 1
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200436} VTermAttrMask;
437
438int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs);
439
440int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell);
441
442int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos);
443
Bram Moolenaarb691de02018-04-24 18:39:14 +0200444// ---------
445// Utilities
446// ---------
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200447
448VTermValueType vterm_get_attr_type(VTermAttr attr);
449VTermValueType vterm_get_prop_type(VTermProp prop);
450
451void vterm_scroll_rect(VTermRect rect,
452 int downward,
453 int rightward,
454 int (*moverect)(VTermRect src, VTermRect dest, void *user),
455 int (*eraserect)(VTermRect rect, int selective, void *user),
456 void *user);
457
458void vterm_copy_cells(VTermRect dest,
459 VTermRect src,
460 void (*copycell)(VTermPos dest, VTermPos src, void *user),
461 void *user);
462
463#ifdef __cplusplus
464}
465#endif
466
467#endif