robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
38986188ba
master
1#pragma once 2 3#include <stdarg.h> 4#include <stdbool.h> 5#include <stdint.h> 6#include <stdlib.h> 7 8#include "nvim/macros_defs.h" 9#include "nvim/types_defs.h" 10#include "nvim/vterm/vterm_defs.h" 11#include "nvim/vterm/vterm_keycodes_defs.h" 12 13#include "vterm/vterm.h.generated.h" 14 15#define VTERM_VERSION_MAJOR 0 16#define VTERM_VERSION_MINOR 3 17 18// move a rect 19static inline void vterm_rect_move (VTermRect * rect ,int row_delta ,int col_delta ) 20{ 21rect -> start_row += row_delta ;rect -> end_row += row_delta ; 22rect -> start_col += col_delta ;rect -> end_col += col_delta ; 23} 24 25// Bit-field describing the content of the tagged union `VTermColor`. 26typedef enum { 27// If the lower bit of `type` is not set, the colour is 24-bit RGB. 28VTERM_COLOR_RGB = 0x00 , 29 30// The colour is an index into a palette of 256 colours. 31VTERM_COLOR_INDEXED = 0x01 , 32 33// Mask that can be used to extract the RGB/Indexed bit. 34VTERM_COLOR_TYPE_MASK = 0x01 , 35 36// If set, indicates that this colour should be the default foreground color, i.e. there was no 37// SGR request for another colour. When rendering this colour it is possible to ignore "idx" and 38// just use a colour that is not in the palette. 39VTERM_COLOR_DEFAULT_FG = 0x02 , 40 41// If set, indicates that this colour should be the default background color, i.e. there was no 42// SGR request for another colour. A common option when rendering this colour is to not render a 43// background at all, for example by rendering the window transparently at this spot. 44VTERM_COLOR_DEFAULT_BG = 0x04 , 45 46// Mask that can be used to extract the default foreground/background bit. 47VTERM_COLOR_DEFAULT_MASK = 0x06 , 48}VTermColorType ; 49 50// Returns true if the VTERM_COLOR_RGB `type` flag is set, indicating that the given VTermColor 51// instance is an indexed colour. 52#define VTERM_COLOR_IS_INDEXED (col ) \ 53 (((col)->type & VTERM_COLOR_TYPE_MASK) == VTERM_COLOR_INDEXED) 54 55// Returns true if the VTERM_COLOR_INDEXED `type` flag is set, indicating that the given VTermColor 56// instance is an rgb colour. 57#define VTERM_COLOR_IS_RGB (col ) \ 58 (((col)->type & VTERM_COLOR_TYPE_MASK) == VTERM_COLOR_RGB) 59 60// Returns true if the VTERM_COLOR_DEFAULT_FG `type` flag is set, indicating that the given 61// VTermColor instance corresponds to the default foreground color. 62#define VTERM_COLOR_IS_DEFAULT_FG (col ) \ 63 (!!((col)->type & VTERM_COLOR_DEFAULT_FG)) 64 65// Returns true if the VTERM_COLOR_DEFAULT_BG `type` flag is set, indicating that the given 66// VTermColor instance corresponds to the default background color. 67#define VTERM_COLOR_IS_DEFAULT_BG (col ) \ 68 (!!((col)->type & VTERM_COLOR_DEFAULT_BG)) 69 70// Constructs a new VTermColor instance representing the given RGB values. 71static inline void vterm_color_rgb (VTermColor * col ,uint8_t red ,uint8_t green ,uint8_t blue ) 72{ 73col -> type = VTERM_COLOR_RGB ; 74col -> rgb .red = red ; 75col -> rgb .green = green ; 76col -> rgb .blue = blue ; 77} 78 79// Construct a new VTermColor instance representing an indexed color with the given index. 80static inline void vterm_color_indexed (VTermColor * col ,uint8_t idx ) 81{ 82col -> type = VTERM_COLOR_INDEXED ; 83col -> indexed .idx = idx ; 84} 85 86// ------------ 87// Parser layer 88// ------------ 89 90/// Flag to indicate non-final subparameters in a single CSI parameter. 91/// Consider 92/// CSI 1;2:3:4;5a 93/// 1 4 and 5 are final. 94/// 2 and 3 are non-final and will have this bit set 95/// 96/// Don't confuse this with the final byte of the CSI escape; 'a' in this case. 97#define CSI_ARG_FLAG_MORE (1U << 31) 98#define CSI_ARG_MASK (~(1U << 31)) 99 100#define CSI_ARG_HAS_MORE (a ) ((a)& CSI_ARG_FLAG_MORE) 101#define CSI_ARG (a ) ((a)& CSI_ARG_MASK) 102 103// Can't use -1 to indicate a missing argument; use this instead 104#define CSI_ARG_MISSING ((1UL<<31) - 1) 105 106#define CSI_ARG_IS_MISSING (a ) (CSI_ARG(a) == CSI_ARG_MISSING) 107#define CSI_ARG_OR (a ,def ) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a)) 108#define CSI_ARG_COUNT (a ) (CSI_ARG(a) == CSI_ARG_MISSING || CSI_ARG(a) == 0 ? 1 : CSI_ARG(a)) 109 110enum { 111VTERM_UNDERLINE_OFF , 112VTERM_UNDERLINE_SINGLE , 113VTERM_UNDERLINE_DOUBLE , 114VTERM_UNDERLINE_CURLY , 115}; 116 117enum { 118VTERM_BASELINE_NORMAL , 119VTERM_BASELINE_RAISE , 120VTERM_BASELINE_LOWER , 121}; 122 123// Back-compat alias for the brief time it was in 0.3-RC1 124#define vterm_screen_set_reflow vterm_screen_enable_reflow 125 126void vterm_scroll_rect (VTermRect rect ,int downward ,int rightward , 127int (* moverect )(VTermRect src ,VTermRect dest ,void * user ), 128int (* eraserect )(VTermRect rect ,int selective ,void * user ),void * user ); 129 130struct VTermScreen { 131VTerm * vt ; 132VTermState * state ; 133 134const VTermScreenCallbacks * callbacks ; 135void * cbdata ; 136 137VTermDamageSize damage_merge ; 138// start_row == -1 => no damage 139VTermRect damaged ; 140VTermRect pending_scrollrect ; 141int pending_scroll_downward ,pending_scroll_rightward ; 142 143int rows ; 144int cols ; 145 146unsigned global_reverse :1 ; 147unsigned reflow :1 ; 148 149// Primary and Altscreen. buffers[1] is lazily allocated as needed 150ScreenCell * buffers [2 ]; 151 152// buffer will == buffers[0] or buffers[1], depending on altscreen 153ScreenCell * buffer ; 154 155// buffer for a single screen row used in scrollback storage callbacks 156VTermScreenCell * sb_buffer ; 157 158ScreenPen pen ; 159};