ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
colorscheme.h
Go to the documentation of this file.
1
30
31#pragma once
32
33/* Storage capacities in elements; text buffers include the terminating NUL. */
34#define OPTIONS_COLORSCHEME_NAME_BUFFER_SIZE 64
35#define OPTIONS_COLORSCHEME_DESCRIPTION_BUFFER_SIZE 256
36#define OPTIONS_COLORSCHEME_FOREGROUND_16_BUFFER_SIZE 16
37#define OPTIONS_COLORSCHEME_FOREGROUND_256_BUFFER_SIZE 24
38#define OPTIONS_COLORSCHEME_FOREGROUND_TRUECOLOR_BUFFER_SIZE 32
39
40/* Existing buffer budgets in bytes, including NUL for text storage. */
41#define COLORSCHEME_LOG_COLOR_COUNT 8
42#define COLORSCHEME_SGR_BUFFER_SIZE 32
43
44#include "../common.h"
46#include <libplatform/mutex.h>
47#include <libplatform/terminal.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/* ============================================================================
54 * Color Definitions
55 * ============================================================================
56 */
57
74
81typedef struct color_scheme_t {
86
87 /* Dark mode colors (default, 8 colors for log levels) */
90
91 /* Light mode colors (optional) */
94
95 /* Metadata */
97 char source_file[PLATFORM_MAX_PATH_LENGTH];
100
124
135
142 terminal_color_mode_t mode);
148void colorscheme_apply(const color_scheme_t *scheme);
149
150/* ============================================================================
151 * Color System API
152 * ============================================================================
153 */
154
162
168void colorscheme_destroy(void);
169
177
187
197 color_scheme_t *scheme);
198
209 color_scheme_t *scheme);
210
223 terminal_color_mode_t mode,
224 terminal_background_t background,
225 compiled_color_scheme_t *compiled);
226
234
244asciichat_error_t colorscheme_export_scheme(const char *scheme_name,
245 const char *file_path);
246
247/* ============================================================================
248 * Color Conversion Utilities
249 * ============================================================================
250 */
251
262asciichat_error_t parse_hex_color(const char *hex, uint8_t *r, uint8_t *g,
263 uint8_t *b);
264
265/* Note: rgb_to_16color() and rgb_to_256color() are defined in
266 * lib/video/ansi_fast.h To use them in colors.c, include ansi_fast.h */
267
278void rgb_to_truecolor_ansi(uint8_t r, uint8_t g, uint8_t b, char *buf,
279 size_t size);
280
281/* ============================================================================
282 * Terminal Background Detection
283 * ============================================================================
284 */
285
297
298/* ============================================================================
299 * Early Color Initialization (for main() before log_init)
300 * ============================================================================
301 */
302
315 const char *const argv[]);
316
317/* ============================================================================
318 * Internal: Shared Mutex for Color Compilation
319 * ============================================================================
320 */
321
329extern mutex_t g_colorscheme_mutex;
330
331#ifdef __cplusplus
332}
333#endif
mutex_t g_colorscheme_mutex
Shared mutex for color scheme compilation.
Definition colorscheme.c:56
#define OPTIONS_COLORSCHEME_FOREGROUND_TRUECOLOR_BUFFER_SIZE
Definition colorscheme.h:38
terminal_background_t colorscheme_current_background(void)
void colorscheme_apply(const color_scheme_t *scheme)
#define OPTIONS_COLORSCHEME_DESCRIPTION_BUFFER_SIZE
Definition colorscheme.h:35
asciichat_error_t options_colorscheme_init_early(int argc, const char *const argv[])
Initialize color scheme early, before logging.
#define OPTIONS_COLORSCHEME_FOREGROUND_256_BUFFER_SIZE
Definition colorscheme.h:37
asciichat_error_t colorscheme_export_scheme(const char *scheme_name, const char *file_path)
Export a color scheme to TOML format.
asciichat_error_t colorscheme_init(void)
Initialize the color system.
#define OPTIONS_COLORSCHEME_FOREGROUND_16_BUFFER_SIZE
Definition colorscheme.h:36
asciichat_error_t parse_hex_color(const char *hex, uint8_t *r, uint8_t *g, uint8_t *b)
Parse a hex color string.
asciichat_error_t colorscheme_load_builtin(const char *name, color_scheme_t *scheme)
Load a built-in color scheme.
const color_scheme_t * colorscheme_get_active_scheme(void)
Get currently active color scheme.
terminal_background_t
Color scheme definition.
Definition colorscheme.h:66
@ TERM_BACKGROUND_DARK
Definition colorscheme.h:71
@ TERM_BACKGROUND_UNKNOWN
Definition colorscheme.h:67
@ TERM_BACKGROUND_LIGHT
Definition colorscheme.h:69
void colorscheme_current_palette(colorscheme_palette_t *palette, terminal_color_mode_t mode)
#define COLORSCHEME_SGR_BUFFER_SIZE
Definition colorscheme.h:42
terminal_background_t detect_terminal_background(void)
Detect terminal background (light or dark).
#define OPTIONS_COLORSCHEME_NAME_BUFFER_SIZE
Definition colorscheme.h:34
asciichat_error_t colorscheme_load_from_file(const char *path, color_scheme_t *scheme)
Load a color scheme from a TOML file.
uint8_t colorscheme_highlight_background(void)
void colorscheme_destroy(void)
Shutdown the color system.
asciichat_error_t colorscheme_set_active_scheme(const char *name)
Set the active color scheme.
asciichat_error_t colorscheme_compile_scheme(const color_scheme_t *scheme, terminal_color_mode_t mode, terminal_background_t background, compiled_color_scheme_t *compiled)
Compile a color scheme to ANSI codes.
void rgb_to_truecolor_ansi(uint8_t r, uint8_t g, uint8_t b, char *buf, size_t size)
Generate truecolor ANSI escape code.
#define COLORSCHEME_LOG_COLOR_COUNT
Definition colorscheme.h:41
void colorscheme_cleanup_compiled(compiled_color_scheme_t *compiled)
Clean up allocated strings in a compiled color scheme.
unsigned char uint8_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
⚙️ Common definitions, error codes, macros, and types shared throughout the application
char file_path[PLATFORM_MAX_PATH_LENGTH]
Definition mmap.c:44
Color scheme definition.
Definition colorscheme.h:81
rgb_pixel_t log_colors_light[8]
Definition colorscheme.h:93
char source_file[PLATFORM_MAX_PATH_LENGTH]
Definition colorscheme.h:97
char description[256]
Definition colorscheme.h:85
rgb_pixel_t log_colors_dark[8]
Definition colorscheme.h:88
char name[64]
Definition colorscheme.h:82
bool has_light_variant
Definition colorscheme.h:92
char background_codes[8][32]
terminal_background_t background
Compiled ANSI escape codes for a color scheme.
const char * codes_16[8]
const char * codes_256[8]
const char * codes_truecolor[8]