neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

vterm.h (5203B)


      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
     19 static inline void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta)
     20 {
     21  rect->start_row += row_delta; rect->end_row += row_delta;
     22  rect->start_col += col_delta; rect->end_col += col_delta;
     23 }
     24 
     25 // Bit-field describing the content of the tagged union `VTermColor`.
     26 typedef enum {
     27  // If the lower bit of `type` is not set, the colour is 24-bit RGB.
     28  VTERM_COLOR_RGB = 0x00,
     29 
     30  // The colour is an index into a palette of 256 colours.
     31  VTERM_COLOR_INDEXED = 0x01,
     32 
     33  // Mask that can be used to extract the RGB/Indexed bit.
     34  VTERM_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.
     39  VTERM_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.
     44  VTERM_COLOR_DEFAULT_BG = 0x04,
     45 
     46  // Mask that can be used to extract the default foreground/background bit.
     47  VTERM_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.
     71 static inline void vterm_color_rgb(VTermColor *col, uint8_t red, uint8_t green, uint8_t blue)
     72 {
     73  col->type = VTERM_COLOR_RGB;
     74  col->rgb.red = red;
     75  col->rgb.green = green;
     76  col->rgb.blue = blue;
     77 }
     78 
     79 // Construct a new VTermColor instance representing an indexed color with the given index.
     80 static inline void vterm_color_indexed(VTermColor *col, uint8_t idx)
     81 {
     82  col->type = VTERM_COLOR_INDEXED;
     83  col->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 
    110 enum {
    111  VTERM_UNDERLINE_OFF,
    112  VTERM_UNDERLINE_SINGLE,
    113  VTERM_UNDERLINE_DOUBLE,
    114  VTERM_UNDERLINE_CURLY,
    115 };
    116 
    117 enum {
    118  VTERM_BASELINE_NORMAL,
    119  VTERM_BASELINE_RAISE,
    120  VTERM_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 
    126 void vterm_scroll_rect(VTermRect rect, int downward, int rightward,
    127                       int (*moverect)(VTermRect src, VTermRect dest, void *user),
    128                       int (*eraserect)(VTermRect rect, int selective, void *user), void *user);
    129 
    130 struct VTermScreen {
    131  VTerm *vt;
    132  VTermState *state;
    133 
    134  const VTermScreenCallbacks *callbacks;
    135  void *cbdata;
    136 
    137  VTermDamageSize damage_merge;
    138  // start_row == -1 => no damage
    139  VTermRect damaged;
    140  VTermRect pending_scrollrect;
    141  int pending_scroll_downward, pending_scroll_rightward;
    142 
    143  int rows;
    144  int cols;
    145 
    146  unsigned global_reverse : 1;
    147  unsigned reflow : 1;
    148 
    149  // Primary and Altscreen. buffers[1] is lazily allocated as needed
    150  ScreenCell *buffers[2];
    151 
    152  // buffer will == buffers[0] or buffers[1], depending on altscreen
    153  ScreenCell *buffer;
    154 
    155  // buffer for a single screen row used in scrollback storage callbacks
    156  VTermScreenCell *sb_buffer;
    157 
    158  ScreenPen pen;
    159 };