mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-22 07:15:19 +00:00
vt: add style C API
Expose the terminal Style struct to the C API as GhosttyStyle, a sized struct with foreground, background, and underline colors (as tagged unions) plus boolean text decoration flags. Add ghostty_style_default() to obtain the default style and ghostty_style_is_default() to check whether a style has all default values. Wire both through c/style.zig, main.zig, and lib_vt.zig with the corresponding header in vt/style.h.
This commit is contained in:
@@ -98,6 +98,7 @@ extern "C" {
|
||||
#include <ghostty/vt/terminal.h>
|
||||
#include <ghostty/vt/osc.h>
|
||||
#include <ghostty/vt/sgr.h>
|
||||
#include <ghostty/vt/style.h>
|
||||
#include <ghostty/vt/key.h>
|
||||
#include <ghostty/vt/modes.h>
|
||||
#include <ghostty/vt/mouse.h>
|
||||
|
||||
128
include/ghostty/vt/style.h
Normal file
128
include/ghostty/vt/style.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @file style.h
|
||||
*
|
||||
* Terminal cell style types.
|
||||
*/
|
||||
|
||||
#ifndef GHOSTTY_VT_STYLE_H
|
||||
#define GHOSTTY_VT_STYLE_H
|
||||
|
||||
#include <ghostty/vt/color.h>
|
||||
#include <ghostty/vt/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup style Style
|
||||
*
|
||||
* Terminal cell style attributes.
|
||||
*
|
||||
* A style describes the visual attributes of a terminal cell, including
|
||||
* foreground, background, and underline colors, as well as flags for
|
||||
* bold, italic, underline, and other text decorations.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Style color tags.
|
||||
*
|
||||
* These values identify the type of color in a style color.
|
||||
* Use the tag to determine which field in the color value union to access.
|
||||
*
|
||||
* @ingroup style
|
||||
*/
|
||||
typedef enum {
|
||||
GHOSTTY_STYLE_COLOR_NONE = 0,
|
||||
GHOSTTY_STYLE_COLOR_PALETTE = 1,
|
||||
GHOSTTY_STYLE_COLOR_RGB = 2,
|
||||
} GhosttyStyleColorTag;
|
||||
|
||||
/**
|
||||
* Style color value union.
|
||||
*
|
||||
* Use the tag to determine which field is active.
|
||||
*
|
||||
* @ingroup style
|
||||
*/
|
||||
typedef union {
|
||||
GhosttyColorPaletteIndex palette;
|
||||
GhosttyColorRgb rgb;
|
||||
uint32_t _padding;
|
||||
} GhosttyStyleColorValue;
|
||||
|
||||
/**
|
||||
* Style color (tagged union).
|
||||
*
|
||||
* A color used in a style attribute. Can be unset (none), a palette
|
||||
* index, or a direct RGB value.
|
||||
*
|
||||
* @ingroup style
|
||||
*/
|
||||
typedef struct {
|
||||
GhosttyStyleColorTag tag;
|
||||
GhosttyStyleColorValue value;
|
||||
} GhosttyStyleColor;
|
||||
|
||||
/**
|
||||
* Terminal cell style.
|
||||
*
|
||||
* Describes the complete visual style for a terminal cell, including
|
||||
* foreground, background, and underline colors, as well as text
|
||||
* decoration flags. The underline field uses the same values as
|
||||
* GhosttySgrUnderline.
|
||||
*
|
||||
* This is a sized struct. Use GHOSTTY_INIT_SIZED() to initialize it.
|
||||
*
|
||||
* @ingroup style
|
||||
*/
|
||||
typedef struct {
|
||||
size_t size;
|
||||
GhosttyStyleColor fg_color;
|
||||
GhosttyStyleColor bg_color;
|
||||
GhosttyStyleColor underline_color;
|
||||
bool bold;
|
||||
bool italic;
|
||||
bool faint;
|
||||
bool blink;
|
||||
bool inverse;
|
||||
bool invisible;
|
||||
bool strikethrough;
|
||||
bool overline;
|
||||
int underline; /**< One of GHOSTTY_SGR_UNDERLINE_* values */
|
||||
} GhosttyStyle;
|
||||
|
||||
/**
|
||||
* Get the default style.
|
||||
*
|
||||
* Initializes the style to the default values (no colors, no flags).
|
||||
*
|
||||
* @param style Pointer to the style to initialize
|
||||
*
|
||||
* @ingroup style
|
||||
*/
|
||||
void ghostty_style_default(GhosttyStyle* style);
|
||||
|
||||
/**
|
||||
* Check if a style is the default style.
|
||||
*
|
||||
* Returns true if all colors are unset and all flags are off.
|
||||
*
|
||||
* @param style Pointer to the style to check
|
||||
* @return true if the style is the default style
|
||||
*
|
||||
* @ingroup style
|
||||
*/
|
||||
bool ghostty_style_is_default(const GhosttyStyle* style);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* GHOSTTY_VT_STYLE_H */
|
||||
Reference in New Issue
Block a user