From f6347ee1e2f822f2e63e46988a6cd70dd2509dad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 Jul 2024 14:41:48 +0530 Subject: [PATCH] Move more declarations out of data-types.h --- kitty/cursor.c | 2 +- kitty/data-types.c | 1 + kitty/data-types.h | 77 ++-------------------------------------------- kitty/history.h | 13 ++++++++ kitty/line.h | 66 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 76 deletions(-) diff --git a/kitty/cursor.c b/kitty/cursor.c index fb5e7d506..6e69d043e 100644 --- a/kitty/cursor.c +++ b/kitty/cursor.c @@ -5,7 +5,7 @@ * Distributed under terms of the GPL3 license. */ -#include "data-types.h" +#include "line.h" #include diff --git a/kitty/data-types.c b/kitty/data-types.c index 37ccc3600..d0ebae69c 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -13,6 +13,7 @@ #endif #include "data-types.h" +#include "line.h" #include "charsets.h" #include "base64.h" #include diff --git a/kitty/data-types.h b/kitty/data-types.h index 41e8da0e1..65d158ef2 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -197,33 +197,6 @@ typedef struct { uint32_t left, top, right, bottom; } Region; -typedef union CellAttrs { - struct { - uint16_t width : 2; - uint16_t decoration : 3; - uint16_t bold : 1; - uint16_t italic : 1; - uint16_t reverse : 1; - uint16_t strike : 1; - uint16_t dim : 1; - uint16_t mark : 2; - uint16_t next_char_was_wrapped : 1; - }; - uint16_t val; -} CellAttrs; -#define MARK_MASK (3u) -#define WIDTH_MASK (3u) -#define DECORATION_MASK (7u) -#define NUM_UNDERLINE_STYLES (5u) -#define SGR_MASK (~(((CellAttrs){.width=WIDTH_MASK, .mark=MARK_MASK, .next_char_was_wrapped=1}).val)) - -typedef struct { - color_type fg, bg, decoration_fg; - sprite_index sprite_x, sprite_y, sprite_z; - CellAttrs attrs; -} GPUCell; -static_assert(sizeof(GPUCell) == 20, "Fix the ordering of GPUCell"); - typedef union CharOrIndex { struct { char_type ch_is_index: 1; @@ -232,36 +205,7 @@ typedef union CharOrIndex { char_type val; } CharOrIndex; -typedef struct { - char_type ch; - hyperlink_id_type hyperlink_id; - combining_type cc_idx[3]; -} CPUCell; -static_assert(sizeof(CPUCell) == 12, "Fix the ordering of CPUCell"); - typedef enum { UNKNOWN_PROMPT_KIND = 0, PROMPT_START = 1, SECONDARY_PROMPT = 2, OUTPUT_START = 3 } PromptKind; -typedef union LineAttrs { - struct { - uint8_t is_continued : 1; - uint8_t has_dirty_text : 1; - uint8_t has_image_placeholders : 1; - PromptKind prompt_kind : 2; - }; - uint8_t val; -} LineAttrs ; - -typedef struct { - GPUCell *gpu_cells; - CPUCell *cpu_cells; - LineAttrs *line_attrs; -} HistoryBufSegment; - -typedef struct { - void *ringbuf; - size_t maximum_size; - bool rewrap_needed; -} PagerHistoryBuf; - typedef struct {int x;} *HYPERLINK_POOL_HANDLE; typedef struct { Py_UCS4 *buf; @@ -309,6 +253,8 @@ typedef struct TransparentDynamicColor { } TransparentDynamicColor; +#define MARK_MASK (3u) + typedef struct { PyObject_HEAD @@ -346,23 +292,6 @@ typedef struct {FONTS_DATA_HEAD} *FONTS_DATA_HANDLE; memmove((array) + (i), (array) + (i) + 1, sizeof((array)[0]) * ((count) - (i))); \ }} -static inline CellAttrs -cursor_to_attrs(const Cursor *c, const uint16_t width) { - CellAttrs ans = { - .width=width, .decoration=c->decoration, .bold=c->bold, .italic=c->italic, .reverse=c->reverse, - .strike=c->strikethrough, .dim=c->dim}; - return ans; -} - -#define cursor_as_gpu_cell(cursor) {.attrs=cursor_to_attrs(cursor, 0), .fg=(cursor->fg & COL_MASK), .bg=(cursor->bg & COL_MASK), .decoration_fg=cursor->decoration_fg & COL_MASK} - -static inline void -attrs_to_cursor(const CellAttrs attrs, Cursor *c) { - c->decoration = attrs.decoration; c->bold = attrs.bold; c->italic = attrs.italic; - c->reverse = attrs.reverse; c->strikethrough = attrs.strike; c->dim = attrs.dim; -} - - // Global functions Cursor* alloc_cursor(void); ColorProfile* alloc_color_profile(void); @@ -374,8 +303,6 @@ Cursor* cursor_copy(Cursor*); void cursor_copy_to(Cursor *src, Cursor *dest); void cursor_reset_display_attrs(Cursor*); void cursor_from_sgr(Cursor *self, int *params, unsigned int count, bool is_group); -void apply_sgr_to_cells(GPUCell *first_cell, unsigned int cell_count, int *params, unsigned int count, bool is_group); -const char* cell_as_sgr(const GPUCell *, const GPUCell *); const char* cursor_as_sgr(const Cursor *); PyObject* cm_thread_write(PyObject *self, PyObject *args); diff --git a/kitty/history.h b/kitty/history.h index b795bea95..c0a63d1f3 100644 --- a/kitty/history.h +++ b/kitty/history.h @@ -9,6 +9,19 @@ #include "line.h" +typedef struct { + GPUCell *gpu_cells; + CPUCell *cpu_cells; + LineAttrs *line_attrs; +} HistoryBufSegment; + +typedef struct { + void *ringbuf; + size_t maximum_size; + bool rewrap_needed; +} PagerHistoryBuf; + + typedef struct { PyObject_HEAD diff --git a/kitty/line.h b/kitty/line.h index 406f76295..04d688576 100644 --- a/kitty/line.h +++ b/kitty/line.h @@ -9,6 +9,52 @@ #include "text-cache.h" +typedef union CellAttrs { + struct { + uint16_t width : 2; + uint16_t decoration : 3; + uint16_t bold : 1; + uint16_t italic : 1; + uint16_t reverse : 1; + uint16_t strike : 1; + uint16_t dim : 1; + uint16_t mark : 2; + uint16_t next_char_was_wrapped : 1; + }; + uint16_t val; +} CellAttrs; + +#define WIDTH_MASK (3u) +#define DECORATION_MASK (7u) +#define NUM_UNDERLINE_STYLES (5u) +#define SGR_MASK (~(((CellAttrs){.width=WIDTH_MASK, .mark=MARK_MASK, .next_char_was_wrapped=1}).val)) + +typedef struct { + color_type fg, bg, decoration_fg; + sprite_index sprite_x, sprite_y, sprite_z; + CellAttrs attrs; +} GPUCell; +static_assert(sizeof(GPUCell) == 20, "Fix the ordering of GPUCell"); + +typedef struct { + char_type ch; + hyperlink_id_type hyperlink_id; + combining_type cc_idx[3]; +} CPUCell; +static_assert(sizeof(CPUCell) == 12, "Fix the ordering of CPUCell"); + + +typedef union LineAttrs { + struct { + uint8_t is_continued : 1; + uint8_t has_dirty_text : 1; + uint8_t has_image_placeholders : 1; + PromptKind prompt_kind : 2; + }; + uint8_t val; +} LineAttrs ; + + typedef struct { PyObject_HEAD @@ -21,3 +67,23 @@ typedef struct { } Line; Line* alloc_line(TextCache *text_cache); +void apply_sgr_to_cells(GPUCell *first_cell, unsigned int cell_count, int *params, unsigned int count, bool is_group); +const char* cell_as_sgr(const GPUCell *, const GPUCell *); + +static inline CellAttrs +cursor_to_attrs(const Cursor *c, const uint16_t width) { + CellAttrs ans = { + .width=width, .decoration=c->decoration, .bold=c->bold, .italic=c->italic, .reverse=c->reverse, + .strike=c->strikethrough, .dim=c->dim}; + return ans; +} + +static inline void +attrs_to_cursor(const CellAttrs attrs, Cursor *c) { + c->decoration = attrs.decoration; c->bold = attrs.bold; c->italic = attrs.italic; + c->reverse = attrs.reverse; c->strikethrough = attrs.strike; c->dim = attrs.dim; +} + +#define cursor_as_gpu_cell(cursor) {.attrs=cursor_to_attrs(cursor, 0), .fg=(cursor->fg & COL_MASK), .bg=(cursor->bg & COL_MASK), .decoration_fg=cursor->decoration_fg & COL_MASK} + +