1/**
2 * @file color.h
3 *
4 * Color types and utilities.
5 */
6
7#ifndef GHOSTTY_VT_COLOR_H
8#define GHOSTTY_VT_COLOR_H
9
10#include <stdint.h>
11#include <ghostty/vt/types.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/**
18 * RGB color value.
19 *
20 * @ingroup sgr
21 */
22typedef struct {
23 uint8_t r; /**< Red component (0-255) */
24 uint8_t g; /**< Green component (0-255) */
25 uint8_t b; /**< Blue component (0-255) */
26} GhosttyColorRgb;
27
28/**
29 * Palette color index (0-255).
30 *
31 * @ingroup sgr
32 */
33typedef uint8_t GhosttyColorPaletteIndex;
34
35/** @addtogroup sgr
36 * @{
37 */
38
39/** Black color (0) @ingroup sgr */
40#define GHOSTTY_COLOR_NAMED_BLACK 0
41/** Red color (1) @ingroup sgr */
42#define GHOSTTY_COLOR_NAMED_RED 1
43/** Green color (2) @ingroup sgr */
44#define GHOSTTY_COLOR_NAMED_GREEN 2
45/** Yellow color (3) @ingroup sgr */
46#define GHOSTTY_COLOR_NAMED_YELLOW 3
47/** Blue color (4) @ingroup sgr */
48#define GHOSTTY_COLOR_NAMED_BLUE 4
49/** Magenta color (5) @ingroup sgr */
50#define GHOSTTY_COLOR_NAMED_MAGENTA 5
51/** Cyan color (6) @ingroup sgr */
52#define GHOSTTY_COLOR_NAMED_CYAN 6
53/** White color (7) @ingroup sgr */
54#define GHOSTTY_COLOR_NAMED_WHITE 7
55/** Bright black color (8) @ingroup sgr */
56#define GHOSTTY_COLOR_NAMED_BRIGHT_BLACK 8
57/** Bright red color (9) @ingroup sgr */
58#define GHOSTTY_COLOR_NAMED_BRIGHT_RED 9
59/** Bright green color (10) @ingroup sgr */
60#define GHOSTTY_COLOR_NAMED_BRIGHT_GREEN 10
61/** Bright yellow color (11) @ingroup sgr */
62#define GHOSTTY_COLOR_NAMED_BRIGHT_YELLOW 11
63/** Bright blue color (12) @ingroup sgr */
64#define GHOSTTY_COLOR_NAMED_BRIGHT_BLUE 12
65/** Bright magenta color (13) @ingroup sgr */
66#define GHOSTTY_COLOR_NAMED_BRIGHT_MAGENTA 13
67/** Bright cyan color (14) @ingroup sgr */
68#define GHOSTTY_COLOR_NAMED_BRIGHT_CYAN 14
69/** Bright white color (15) @ingroup sgr */
70#define GHOSTTY_COLOR_NAMED_BRIGHT_WHITE 15
71
72/** @} */
73
74/**
75 * Get the RGB color components.
76 *
77 * This function extracts the individual red, green, and blue components
78 * from a GhosttyColorRgb value. Primarily useful in WebAssembly environments
79 * where accessing struct fields directly is difficult.
80 *
81 * @param color The RGB color value
82 * @param r Pointer to store the red component (0-255)
83 * @param g Pointer to store the green component (0-255)
84 * @param b Pointer to store the blue component (0-255)
85 *
86 * @ingroup sgr
87 */
88GHOSTTY_API void ghostty_color_rgb_get(GhosttyColorRgb color,
89 uint8_t* r,
90 uint8_t* g,
91 uint8_t* b);
92
93#ifdef __cplusplus
94}
95#endif
96
97#endif /* GHOSTTY_VT_COLOR_H */