diff options
Diffstat (limited to 'src/nvim/decoration_defs.h')
-rw-r--r-- | src/nvim/decoration_defs.h | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/nvim/decoration_defs.h b/src/nvim/decoration_defs.h new file mode 100644 index 0000000000..d73fd669b7 --- /dev/null +++ b/src/nvim/decoration_defs.h @@ -0,0 +1,129 @@ +#pragma once + +#include <stdint.h> + +#include "klib/kvec.h" + +#define DECOR_ID_INVALID UINT32_MAX + +typedef struct { + char *text; + int hl_id; +} VirtTextChunk; + +typedef kvec_t(VirtTextChunk) VirtText; +#define VIRTTEXT_EMPTY ((VirtText)KV_INITIAL_VALUE) + +typedef enum { + kVPosEndOfLine, + kVPosOverlay, + kVPosWinCol, + kVPosRightAlign, + kVPosInline, +} VirtTextPos; + +typedef kvec_t(struct virt_line { VirtText line; bool left_col; }) VirtLines; + +typedef uint16_t DecorPriority; +#define DECOR_PRIORITY_BASE 0x1000 + +typedef enum { + kHlModeUnknown, + kHlModeReplace, + kHlModeCombine, + kHlModeBlend, +} HlMode; + +enum { + kSHIsSign = 1, + kSHHlEol = 2, + kSHUIWatched = 4, + kSHUIWatchedOverlay = 8, + kSHSpellOn = 16, + kSHSpellOff = 32, + kSHConceal = 64, + kSHConcealAlloc = 128, +}; + +typedef struct { + uint16_t flags; + DecorPriority priority; + int hl_id; + char conceal_char[4]; +} DecorHighlightInline; + +#define DECOR_HIGHLIGHT_INLINE_INIT { 0, DECOR_PRIORITY_BASE, 0, { 0 } } +typedef struct { + uint16_t flags; + DecorPriority priority; + int hl_id; // if sign: highlight of sign text + // TODO(bfredl): Later this should be schar_T[2], but then it needs to handle + // invalidations of the cache + union { + // for now: + // 1. sign is always allocated (drawline.c expects a `char *` for a sign) + // 2. conceal char is allocated if larger than 8 bytes. + char *ptr; // sign or conceal text + char data[8]; + } text; + // NOTE: if more functionality is added to a Highlight these should be overloaded + // or restructured + char *sign_name; + int sign_add_id; + int number_hl_id; + int line_hl_id; + int cursorline_hl_id; + uint32_t next; +} DecorSignHighlight; + +#define DECOR_SIGN_HIGHLIGHT_INIT { 0, DECOR_PRIORITY_BASE, 0, { .ptr = NULL }, NULL, 0, 0, 0, 0, \ + DECOR_ID_INVALID } + +enum { + kVTIsLines = 1, + kVTHide = 2, + kVTLinesAbove = 4, +}; + +typedef struct DecorVirtText DecorVirtText; +struct DecorVirtText { + uint8_t flags; + uint8_t hl_mode; + DecorPriority priority; + int width; // width of virt_text + int col; + VirtTextPos pos; + // TODO(bfredl): reduce this to one datatype, later + union { + VirtText virt_text; + VirtLines virt_lines; + } data; + DecorVirtText *next; +}; +#define DECOR_VIRT_TEXT_INIT { 0, kHlModeUnknown, DECOR_PRIORITY_BASE, 0, 0, kVPosEndOfLine, \ + { .virt_text = KV_INITIAL_VALUE }, NULL, } +#define DECOR_VIRT_LINES_INIT { kVTIsLines, kHlModeUnknown, DECOR_PRIORITY_BASE, 0, 0, \ + kVPosEndOfLine, { .virt_lines = KV_INITIAL_VALUE }, NULL, } + +typedef struct { + uint32_t sh_idx; + DecorVirtText *vt; +} DecorExt; + +// Stored inline in marktree, with MT_FLAG_DECOR_EXT in MTKey.flags +typedef union { + DecorHighlightInline hl; + DecorExt ext; +} DecorInlineData; + +// Not stored in the marktree, but used when passing around args +// +// Convention: an empty "no decoration" value should always be encoded +// with ext=false and an unset DecorHighlightInline (no flags, no hl_id) +typedef struct { + bool ext; + DecorInlineData data; +} DecorInline; + +// initializes in a valid state for the DecorHighlightInline branch +#define DECOR_INLINE_INIT { .ext = false, .data.hl = DECOR_HIGHLIGHT_INLINE_INIT } |