libghostty-vt 0.0.0
Loading...
Searching...
No Matches

Read a cell's colors and text attributes. More...

Detailed Description

Read a cell's colors and text attributes.

A GhosttyStyle is how a cell looks: its foreground, background, and underline colors, and flags for bold, italic, underline, and other text decorations.

You get one from ghostty_grid_ref_style(), or from a render state when you draw. Its colors can be unset, which means you use your default.

Example

ghostty_grid_ref_style(&ref, &style);
bool bold = style.flags & GHOSTTY_STYLE_FLAG_BOLD;
GHOSTTY_API GhosttyResult ghostty_grid_ref_style(const GhosttyGridRef *ref, GhosttyStyle *out_style)
#define GHOSTTY_STYLE_FLAG_BOLD
Definition style.h:140
GhosttyStyleFlags flags
Definition style.h:238

Full program: c-vt-grid-traverse/src/main.c

See the Grid guide.

Typedefs

typedef uint16_t GhosttyStyleId
typedef uint16_t GhosttyStyleFlags

Enumerations

enum  GhosttyStyleColorTag

Functions

GHOSTTY_API void ghostty_style_default (GhosttyStyle *style)
GHOSTTY_API bool ghostty_style_is_default (const GhosttyStyle *style)

Macros

#define GHOSTTY_STYLE_FLAG_BOLD   ((GhosttyStyleFlags)(1u << 0))
#define GHOSTTY_STYLE_FLAG_ITALIC   ((GhosttyStyleFlags)(1u << 1))
#define GHOSTTY_STYLE_FLAG_FAINT   ((GhosttyStyleFlags)(1u << 2))
#define GHOSTTY_STYLE_FLAG_BLINK   ((GhosttyStyleFlags)(1u << 3))
#define GHOSTTY_STYLE_FLAG_INVERSE   ((GhosttyStyleFlags)(1u << 4))
#define GHOSTTY_STYLE_FLAG_INVISIBLE   ((GhosttyStyleFlags)(1u << 5))
#define GHOSTTY_STYLE_FLAG_STRIKETHROUGH   ((GhosttyStyleFlags)(1u << 6))
#define GHOSTTY_STYLE_FLAG_OVERLINE   ((GhosttyStyleFlags)(1u << 7))
#define GHOSTTY_STYLE_UNDERLINE_SHIFT   8
#define GHOSTTY_STYLE_UNDERLINE_MASK   ((GhosttyStyleFlags)(0x7u << GHOSTTY_STYLE_UNDERLINE_SHIFT))
#define GHOSTTY_STYLE_UNDERLINE(style)

Data Structures

union  GhosttyStyleColorValue
struct  GhosttyStyleColor
struct  GhosttyStyle

Typedef Documentation

◆ GhosttyStyleFlags

typedef uint16_t GhosttyStyleFlags

Style flags.

A 16-bit set of text attributes, laid out as follows:

Bits Meaning
0 to 7 On/off attributes, one GHOSTTY_STYLE_FLAG_* per bit
8 to 10 Underline style, a GhosttySgrUnderline value
11 to 15 Reserved, always zero

Test an attribute with a bitwise AND against its GHOSTTY_STYLE_FLAG_* mask. Read the underline style with GHOSTTY_STYLE_UNDERLINE().

Definition at line 137 of file style.h.

◆ GhosttyStyleId

typedef uint16_t GhosttyStyleId

Style identifier type.

Used to look up the full style from a grid reference. Obtain this from a cell via GHOSTTY_CELL_DATA_STYLE_ID.

Definition at line 51 of file style.h.

Enumeration Type Documentation

◆ GhosttyStyleColorTag

Style color tags.

Identifies which kind of color a GhosttyStyleColor holds. The tag is stored in the one-byte tag field of GhosttyStyleColor, so compare that field against these values.

Definition at line 62 of file style.h.

Function Documentation

◆ ghostty_style_default()

GHOSTTY_API void ghostty_style_default ( GhosttyStyle * style)

Get the default style.

Initializes the style to the default values (no colors, no flags). The default style is all zero bytes.

Parameters
stylePointer to the style to initialize

◆ ghostty_style_is_default()

GHOSTTY_API bool ghostty_style_is_default ( const GhosttyStyle * style)

Check if a style is the default style.

Returns true if all colors are unset and all flags are off. Reserved bits are ignored.

Parameters
stylePointer to the style to check
Returns
true if the style is the default style

Macro Definition Documentation

◆ GHOSTTY_STYLE_FLAG_BLINK

#define GHOSTTY_STYLE_FLAG_BLINK   ((GhosttyStyleFlags)(1u << 3))

Blinking text.

Definition at line 146 of file style.h.

◆ GHOSTTY_STYLE_FLAG_BOLD

#define GHOSTTY_STYLE_FLAG_BOLD   ((GhosttyStyleFlags)(1u << 0))

Bold text.

Examples
c-vt-grid-traverse/src/main.c, c-vt-render/src/main.c, and c-vt-stream/src/main.c.

Definition at line 140 of file style.h.

◆ GHOSTTY_STYLE_FLAG_FAINT

#define GHOSTTY_STYLE_FLAG_FAINT   ((GhosttyStyleFlags)(1u << 2))

Faint (dim) text.

Definition at line 144 of file style.h.

◆ GHOSTTY_STYLE_FLAG_INVERSE

#define GHOSTTY_STYLE_FLAG_INVERSE   ((GhosttyStyleFlags)(1u << 4))

Inverse text, with the foreground and background swapped.

Definition at line 148 of file style.h.

◆ GHOSTTY_STYLE_FLAG_INVISIBLE

#define GHOSTTY_STYLE_FLAG_INVISIBLE   ((GhosttyStyleFlags)(1u << 5))

Invisible (hidden) text.

Definition at line 150 of file style.h.

◆ GHOSTTY_STYLE_FLAG_ITALIC

#define GHOSTTY_STYLE_FLAG_ITALIC   ((GhosttyStyleFlags)(1u << 1))

Italic text.

Definition at line 142 of file style.h.

◆ GHOSTTY_STYLE_FLAG_OVERLINE

#define GHOSTTY_STYLE_FLAG_OVERLINE   ((GhosttyStyleFlags)(1u << 7))

Overlined text.

Definition at line 154 of file style.h.

◆ GHOSTTY_STYLE_FLAG_STRIKETHROUGH

#define GHOSTTY_STYLE_FLAG_STRIKETHROUGH   ((GhosttyStyleFlags)(1u << 6))

Strikethrough text.

Definition at line 152 of file style.h.

◆ GHOSTTY_STYLE_UNDERLINE

#define GHOSTTY_STYLE_UNDERLINE ( style)
Value:
((int)(((style).flags & GHOSTTY_STYLE_UNDERLINE_MASK) >> \
#define GHOSTTY_STYLE_UNDERLINE_MASK
Definition style.h:168
#define GHOSTTY_STYLE_UNDERLINE_SHIFT
Definition style.h:161

Get the underline style of a GhosttyStyle.

The result is a GhosttySgrUnderline value. GHOSTTY_SGR_UNDERLINE_NONE (zero) means the text is not underlined, so the result can also be used as a true/false check.

switch (GHOSTTY_STYLE_UNDERLINE(style)) {
case GHOSTTY_SGR_UNDERLINE_NONE: break;
case GHOSTTY_SGR_UNDERLINE_CURLY: draw_curly_underline(); break;
default: draw_straight_underline(); break;
}
#define GHOSTTY_STYLE_UNDERLINE(style)
Definition style.h:191
Parameters
styleA GhosttyStyle value, not a pointer to one
Returns
The underline style as an int
Examples
c-vt-render/src/main.c.

Definition at line 191 of file style.h.

◆ GHOSTTY_STYLE_UNDERLINE_MASK

#define GHOSTTY_STYLE_UNDERLINE_MASK   ((GhosttyStyleFlags)(0x7u << GHOSTTY_STYLE_UNDERLINE_SHIFT))

The bits of GhosttyStyleFlags that hold the underline style.

Definition at line 168 of file style.h.

◆ GHOSTTY_STYLE_UNDERLINE_SHIFT

#define GHOSTTY_STYLE_UNDERLINE_SHIFT   8

The lowest bit of the underline style in GhosttyStyleFlags.

Definition at line 161 of file style.h.