15b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#ifndef __VTERM_H__ 25b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#define __VTERM_H__ 35b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 45b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#ifdef __cplusplus 55b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyextern "C" { 65b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#endif 75b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 85b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#include <stdint.h> 95b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#include <stdlib.h> 105b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 115b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#include "vterm_input.h" 125b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 135b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct VTerm VTerm; 145b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct VTermState VTermState; 155b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct VTermScreen VTermScreen; 165b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 175b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct { 185b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int row; 195b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int col; 205b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermPos; 215b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 225b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey/* some small utility functions; we can just keep these static here */ 235b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 245b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey/* order points by on-screen flow order */ 255b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeystatic inline int vterm_pos_cmp(VTermPos a, VTermPos b) 265b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey{ 275b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey return (a.row == b.row) ? a.col - b.col : a.row - b.row; 285b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} 295b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 305b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct { 315b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int start_row; 325b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int end_row; 335b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int start_col; 345b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int end_col; 355b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermRect; 365b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 375b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey/* true if the rect contains the point */ 385b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeystatic inline int vterm_rect_contains(VTermRect r, VTermPos p) 395b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey{ 405b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey return p.row >= r.start_row && p.row < r.end_row && 415b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey p.col >= r.start_col && p.col < r.end_col; 425b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} 435b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 445b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey/* move a rect */ 455b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeystatic inline void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta) 465b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey{ 475b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey rect->start_row += row_delta; rect->end_row += row_delta; 485b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey rect->start_col += col_delta; rect->end_col += col_delta; 495b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} 505b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 515b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct { 525b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey uint8_t red, green, blue; 535b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermColor; 545b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 555b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef enum { 565b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey /* VTERM_VALUETYPE_NONE = 0 */ 575b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_VALUETYPE_BOOL = 1, 585b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_VALUETYPE_INT, 595b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_VALUETYPE_STRING, 605b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_VALUETYPE_COLOR, 615b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermValueType; 625b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 635b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef union { 645b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int boolean; 655b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int number; 665b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey char *string; 675b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTermColor color; 685b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermValue; 695b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 705b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef enum { 715b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey /* VTERM_ATTR_NONE = 0 */ 725b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_BOLD = 1, // bool: 1, 22 735b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_UNDERLINE, // number: 4, 21, 24 745b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_ITALIC, // bool: 3, 23 755b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_BLINK, // bool: 5, 25 765b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_REVERSE, // bool: 7, 27 775b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_STRIKE, // bool: 9, 29 785b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_FONT, // number: 10-19 795b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_FOREGROUND, // color: 30-39 90-97 805b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_ATTR_BACKGROUND, // color: 40-49 100-107 815b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermAttr; 825b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 835b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef enum { 845b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey /* VTERM_PROP_NONE = 0 */ 855b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_CURSORVISIBLE = 1, // bool 865b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_CURSORBLINK, // bool 875b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_ALTSCREEN, // bool 885b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_TITLE, // string 895b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_ICONNAME, // string 905b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_REVERSE, // bool 915b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_CURSORSHAPE, // number 925b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermProp; 935b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 945b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyenum { 955b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_CURSORSHAPE_BLOCK = 1, 965b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_CURSORSHAPE_UNDERLINE, 975b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_PROP_CURSORSHAPE_BAR_LEFT, 985b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey}; 995b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 1005b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef void (*VTermMouseFunc)(int x, int y, int button, int pressed, int modifiers, void *data); 1015b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 1025b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct { 1035b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey const uint32_t *chars; 1045b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int width; 10573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int protected_cell:1; /* DECSCA-protected against DECSEL/DECSED */ 1066d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes unsigned int dwl:1; /* DECDWL or DECDHL double-width line */ 1076d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes unsigned int dhl:2; /* DECDHL double-height line (1=top 2=bottom) */ 1085b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermGlyphInfo; 1095b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 1105b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef struct { 1116d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes unsigned int doublewidth:1; /* DECDWL or DECDHL line */ 1126d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes unsigned int doubleheight:2; /* DECDHL line (1=top 2=bottom) */ 1136d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes} VTermLineInfo; 1146d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes 1156d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughestypedef struct { 1165b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey /* libvterm relies on this memory to be zeroed out before it is returned 1175b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey * by the allocator. */ 1185b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey void *(*malloc)(size_t size, void *allocdata); 1195b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey void (*free)(void *ptr, void *allocdata); 1205b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermAllocatorFunctions; 1215b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 1225b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff SharkeyVTerm *vterm_new(int rows, int cols); 1235b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff SharkeyVTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata); 1245b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_free(VTerm* vt); 1255b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 1265b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_get_size(const VTerm *vt, int *rowsp, int *colsp); 1275b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_set_size(VTerm *vt, int rows, int cols); 1285b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 12973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeyvoid vterm_push_bytes(VTerm *vt, const char *bytes, size_t len); 13073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 13173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeyvoid vterm_input_push_char(VTerm *vt, VTermModifier state, uint32_t c); 13273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeyvoid vterm_input_push_key(VTerm *vt, VTermModifier state, VTermKey key); 13373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 13473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeysize_t vterm_output_bufferlen(VTerm *vt); /* deprecated */ 13573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 13673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeysize_t vterm_output_get_buffer_size(const VTerm *vt); 13773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeysize_t vterm_output_get_buffer_current(const VTerm *vt); 13873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeysize_t vterm_output_get_buffer_remaining(const VTerm *vt); 13973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 14073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeysize_t vterm_output_bufferread(VTerm *vt, char *buffer, size_t len); 14173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 14273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// ------------ 14373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// Parser layer 14473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// ------------ 14573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 14673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey/* Flag to indicate non-final subparameters in a single CSI parameter. 14773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey * Consider 14873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey * CSI 1;2:3:4;5a 14973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey * 1 4 and 5 are final. 15073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey * 2 and 3 are non-final and will have this bit set 15173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey * 15273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey * Don't confuse this with the final byte of the CSI escape; 'a' in this case. 15373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey */ 15473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG_FLAG_MORE (1<<31) 15573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG_MASK (~(1<<31)) 15673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 15773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG_HAS_MORE(a) ((a) & CSI_ARG_FLAG_MORE) 15873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG(a) ((a) & CSI_ARG_MASK) 15973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 16073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey/* Can't use -1 to indicate a missing argument; use this instead */ 16173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG_MISSING ((1UL<<31)-1) 16273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 16373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING) 16473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG_OR(a,def) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a)) 16573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define CSI_ARG_COUNT(a) (CSI_ARG(a) == CSI_ARG_MISSING || CSI_ARG(a) == 0 ? 1 : CSI_ARG(a)) 16673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 16773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeytypedef struct { 16873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*text)(const char *bytes, size_t len, void *user); 16973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*control)(unsigned char control, void *user); 17073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*escape)(const char *bytes, size_t len, void *user); 17173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*csi)(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user); 17273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*osc)(const char *command, size_t cmdlen, void *user); 17373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*dcs)(const char *command, size_t cmdlen, void *user); 17473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*resize)(int rows, int cols, void *user); 17573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey} VTermParserCallbacks; 17673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 1775b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_set_parser_callbacks(VTerm *vt, const VTermParserCallbacks *callbacks, void *user); 1785b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 17973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeyvoid vterm_parser_set_utf8(VTerm *vt, int is_utf8); 18073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 18173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// ----------- 18273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// State layer 18373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// ----------- 18473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 18573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeytypedef struct { 18673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*putglyph)(VTermGlyphInfo *info, VTermPos pos, void *user); 18773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user); 18873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*scrollrect)(VTermRect rect, int downward, int rightward, void *user); 18973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*moverect)(VTermRect dest, VTermRect src, void *user); 19073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*erase)(VTermRect rect, int selective, void *user); 19173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*initpen)(void *user); 19273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*setpenattr)(VTermAttr attr, VTermValue *val, void *user); 19373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*settermprop)(VTermProp prop, VTermValue *val, void *user); 19473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*setmousefunc)(VTermMouseFunc func, void *data, void *user); 19573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*bell)(void *user); 19673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*resize)(int rows, int cols, VTermPos *delta, void *user); 1976d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user); 19873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey} VTermStateCallbacks; 19973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 2005b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff SharkeyVTermState *vterm_obtain_state(VTerm *vt); 2015b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2025b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_state_reset(VTermState *state, int hard); 2035b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_state_set_callbacks(VTermState *state, const VTermStateCallbacks *callbacks, void *user); 2045b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos); 2055b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg); 2065b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col); 2075b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg); 2086d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughesvoid vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col); 2095b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright); 2105b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyint vterm_state_get_penattr(const VTermState *state, VTermAttr attr, VTermValue *val); 2115b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyint vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val); 2126d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughesconst VTermLineInfo *vterm_state_get_lineinfo(const VTermState *state, int row); 2135b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 21473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// ------------ 21573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// Screen layer 21673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// ------------ 21773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 21873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeytypedef struct { 21973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey#define VTERM_MAX_CHARS_PER_CELL 6 22073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey uint32_t chars[VTERM_MAX_CHARS_PER_CELL]; 22173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey char width; 22273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey struct { 22373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int bold : 1; 22473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int underline : 2; 22573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int italic : 1; 22673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int blink : 1; 22773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int reverse : 1; 22873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int strike : 1; 22973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey unsigned int font : 4; /* 0 to 9 */ 2306d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes unsigned int dwl : 1; /* On a DECDWL or DECDHL line */ 2316d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes unsigned int dhl : 2; /* On a DECDHL line (1=top 2=bottom) */ 23273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey } attrs; 23373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTermColor fg, bg; 23473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey} VTermScreenCell; 23573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 23673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeytypedef struct { 23773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*damage)(VTermRect rect, void *user); 23873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*moverect)(VTermRect dest, VTermRect src, void *user); 23973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*movecursor)(VTermPos pos, VTermPos oldpos, int visible, void *user); 24073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*settermprop)(VTermProp prop, VTermValue *val, void *user); 24173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*setmousefunc)(VTermMouseFunc func, void *data, void *user); 24273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*bell)(void *user); 24373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*resize)(int rows, int cols, void *user); 24473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user); 24573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey int (*sb_popline)(int cols, VTermScreenCell *cells, void *user); 24673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey} VTermScreenCallbacks; 2475b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2485b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff SharkeyVTermScreen *vterm_obtain_screen(VTerm *vt); 2495b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2505b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen); 2515b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *user); 2525b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2535b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeytypedef enum { 2545b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_DAMAGE_CELL, /* every cell */ 2555b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_DAMAGE_ROW, /* entire rows */ 2565b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_DAMAGE_SCREEN, /* entire screen */ 2575b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTERM_DAMAGE_SCROLL, /* entire screen + scrollrect */ 2585b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} VTermDamageSize; 2595b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2605b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_screen_flush_damage(VTermScreen *screen); 2615b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_screen_set_damage_merge(VTermScreen *screen, VTermDamageSize size); 2625b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2635b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_screen_reset(VTermScreen *screen, int hard); 2646d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes 2656d78f36633063dad0689ca42be1ad8d0313ebfabElliott Hughes/* Neither of these functions NUL-terminate the buffer */ 2665b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeysize_t vterm_screen_get_chars(const VTermScreen *screen, uint32_t *chars, size_t len, const VTermRect rect); 2675b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeysize_t vterm_screen_get_text(const VTermScreen *screen, char *str, size_t len, const VTermRect rect); 2685b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 26973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeytypedef enum { 27073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_BOLD_MASK = 1 << 0, 27173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_UNDERLINE_MASK = 1 << 1, 27273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_ITALIC_MASK = 1 << 2, 27373fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_BLINK_MASK = 1 << 3, 27473fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_REVERSE_MASK = 1 << 4, 27573fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_STRIKE_MASK = 1 << 5, 27673fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_FONT_MASK = 1 << 6, 27773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_FOREGROUND_MASK = 1 << 7, 27873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey VTERM_ATTR_BACKGROUND_MASK = 1 << 8, 27973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey} VTermAttrMask; 28073fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey 28173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkeyint vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs); 2825b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2835b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyint vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell); 2845b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2855b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyint vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos); 2865b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 28773fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// --------- 28873fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// Utilities 28973fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff Sharkey// --------- 2905b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 29173fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff SharkeyVTermValueType vterm_get_attr_type(VTermAttr attr); 29273fbfc38792bd96137d5b6ae3016dfc4d9805d46Jeff SharkeyVTermValueType vterm_get_prop_type(VTermProp prop); 2935b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 2945b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_scroll_rect(VTermRect rect, 2955b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int downward, 2965b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int rightward, 2975b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int (*moverect)(VTermRect src, VTermRect dest, void *user), 2985b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey int (*eraserect)(VTermRect rect, int selective, void *user), 2995b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey void *user); 3005b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 3015b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkeyvoid vterm_copy_cells(VTermRect dest, 3025b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey VTermRect src, 3035b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey void (*copycell)(VTermPos dest, VTermPos src, void *user), 3045b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey void *user); 3055b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 3065b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#ifdef __cplusplus 3075b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey} 3085b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#endif 3095b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey 3105b78a3aa7741c3f44b676ccffa765cecee1cbd4cJeff Sharkey#endif 311