1/**
2 * @file style.h
3 *
4 * Terminal cell style types.
5 */
6
7#ifndef GHOSTTY_VT_STYLE_H
8#define GHOSTTY_VT_STYLE_H
9
10#include <ghostty/vt/color.h>
11#include <ghostty/vt/types.h>
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/** @defgroup style Style
21 *
22 * Terminal cell style attributes.
23 *
24 * A style describes the visual attributes of a terminal cell, including
25 * foreground, background, and underline colors, as well as flags for
26 * bold, italic, underline, and other text decorations.
27 *
28 * @{
29 */
30
31/**
32 * Style identifier type.
33 *
34 * Used to look up the full style from a grid reference.
35 * Obtain this from a cell via GHOSTTY_CELL_DATA_STYLE_ID.
36 *
37 * @ingroup style
38 */
39typedef uint16_t GhosttyStyleId;
40
41/**
42 * Style color tags.
43 *
44 * These values identify the type of color in a style color.
45 * Use the tag to determine which field in the color value union to access.
46 *
47 * @ingroup style
48 */
49typedef enum GHOSTTY_ENUM_TYPED {
50 GHOSTTY_STYLE_COLOR_NONE = 0,
51 GHOSTTY_STYLE_COLOR_PALETTE = 1,
52 GHOSTTY_STYLE_COLOR_RGB = 2,
53 GHOSTTY_STYLE_COLOR_TAG_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
54 } GhosttyStyleColorTag;
55
56/**
57 * Style color value union.
58 *
59 * Use the tag to determine which field is active.
60 *
61 * @ingroup style
62 */
63typedef union {
64 GhosttyColorPaletteIndex palette;
65 GhosttyColorRgb rgb;
66 uint64_t _padding;
67} GhosttyStyleColorValue;
68
69/**
70 * Style color (tagged union).
71 *
72 * A color used in a style attribute. Can be unset (none), a palette
73 * index, or a direct RGB value.
74 *
75 * @ingroup style
76 */
77typedef struct {
78 GhosttyStyleColorTag tag;
79 GhosttyStyleColorValue value;
80} GhosttyStyleColor;
81
82/**
83 * Terminal cell style.
84 *
85 * Describes the complete visual style for a terminal cell, including
86 * foreground, background, and underline colors, as well as text
87 * decoration flags. The underline field uses the same values as
88 * GhosttySgrUnderline.
89 *
90 * This is a sized struct. Use GHOSTTY_INIT_SIZED() to initialize it.
91 *
92 * @ingroup style
93 */
94typedef struct {
95 size_t size;
96 GhosttyStyleColor fg_color;
97 GhosttyStyleColor bg_color;
98 GhosttyStyleColor underline_color;
99 bool bold;
100 bool italic;
101 bool faint;
102 bool blink;
103 bool inverse;
104 bool invisible;
105 bool strikethrough;
106 bool overline;
107 int underline; /**< One of GHOSTTY_SGR_UNDERLINE_* values */
108} GhosttyStyle;
109
110/**
111 * Get the default style.
112 *
113 * Initializes the style to the default values (no colors, no flags).
114 *
115 * @param style Pointer to the style to initialize
116 *
117 * @ingroup style
118 */
119GHOSTTY_API void ghostty_style_default(GhosttyStyle* style);
120
121/**
122 * Check if a style is the default style.
123 *
124 * Returns true if all colors are unset and all flags are off.
125 *
126 * @param style Pointer to the style to check
127 * @return true if the style is the default style
128 *
129 * @ingroup style
130 */
131GHOSTTY_API bool ghostty_style_is_default(const GhosttyStyle* style);
132
133#ifdef __cplusplus
134}
135#endif
136
137/** @} */
138
139#endif /* GHOSTTY_VT_STYLE_H */