ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
colorscheme.h
Go to the documentation of this file.
1
29
30#pragma once
31
32/* Storage capacities in elements; text buffers include the terminating NUL. */
33#define OPTIONS_COLORSCHEME_NAME_BUFFER_SIZE 64
34#define OPTIONS_COLORSCHEME_DESCRIPTION_BUFFER_SIZE 256
35#define OPTIONS_COLORSCHEME_FOREGROUND_16_BUFFER_SIZE 16
36#define OPTIONS_COLORSCHEME_FOREGROUND_256_BUFFER_SIZE 24
37#define OPTIONS_COLORSCHEME_FOREGROUND_TRUECOLOR_BUFFER_SIZE 32
38
39/* Existing buffer budgets in bytes, including NUL for text storage. */
40#define COLORSCHEME_LOG_COLOR_COUNT 8
41#define COLORSCHEME_SGR_BUFFER_SIZE 32
42
43#include "../common.h"
44#include <libplatform/terminal.h>
45#include <libplatform/mutex.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/* ============================================================================
53 * Color Definitions
54 * ============================================================================ */
55
69
76typedef struct color_scheme_t {
79
80 /* Dark mode colors (default, 8 colors for log levels) */
82
83 /* Light mode colors (optional) */
86
87 /* Metadata */
91
108
117
123void colorscheme_current_palette(colorscheme_palette_t *palette, terminal_color_mode_t mode);
128void colorscheme_apply(const color_scheme_t *scheme);
129
130/* ============================================================================
131 * Color System API
132 * ============================================================================ */
133
141
147void colorscheme_destroy(void);
148
156
166
176
187
199asciichat_error_t colorscheme_compile_scheme(const color_scheme_t *scheme, terminal_color_mode_t mode,
200 terminal_background_t background, compiled_color_scheme_t *compiled);
201
209
218asciichat_error_t colorscheme_export_scheme(const char *scheme_name, const char *file_path);
219
220/* ============================================================================
221 * Color Conversion Utilities
222 * ============================================================================ */
223
234asciichat_error_t parse_hex_color(const char *hex, uint8_t *r, uint8_t *g, uint8_t *b);
235
236/* Note: rgb_to_16color() and rgb_to_256color() are defined in lib/video/ansi_fast.h
237 * To use them in colors.c, include ansi_fast.h */
238
249void rgb_to_truecolor_ansi(uint8_t r, uint8_t g, uint8_t b, char *buf, size_t size);
250
251/* ============================================================================
252 * Terminal Background Detection
253 * ============================================================================ */
254
266
267/* ============================================================================
268 * Early Color Initialization (for main() before log_init)
269 * ============================================================================ */
270
282asciichat_error_t options_colorscheme_init_early(int argc, const char *const argv[]);
283
284/* ============================================================================
285 * Internal: Shared Mutex for Color Compilation
286 * ============================================================================ */
287
295extern mutex_t g_colorscheme_mutex;
296
297#ifdef __cplusplus
298}
299#endif
mutex_t g_colorscheme_mutex
Shared mutex for color scheme compilation.
Definition colorscheme.c:50
#define OPTIONS_COLORSCHEME_FOREGROUND_TRUECOLOR_BUFFER_SIZE
Definition colorscheme.h:37
terminal_background_t colorscheme_current_background(void)
void colorscheme_apply(const color_scheme_t *scheme)
#define OPTIONS_COLORSCHEME_DESCRIPTION_BUFFER_SIZE
Definition colorscheme.h:34
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:36
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:35
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:64
@ TERM_BACKGROUND_DARK
Definition colorscheme.h:67
@ TERM_BACKGROUND_UNKNOWN
Definition colorscheme.h:65
@ TERM_BACKGROUND_LIGHT
Definition colorscheme.h:66
void colorscheme_current_palette(colorscheme_palette_t *palette, terminal_color_mode_t mode)
#define COLORSCHEME_SGR_BUFFER_SIZE
Definition colorscheme.h:41
terminal_background_t detect_terminal_background(void)
Detect terminal background (light or dark).
#define OPTIONS_COLORSCHEME_NAME_BUFFER_SIZE
Definition colorscheme.h:33
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:40
void colorscheme_cleanup_compiled(compiled_color_scheme_t *compiled)
Clean up allocated strings in a compiled color scheme.
⚙️ Common definitions, error codes, macros, and types shared throughout the application
#define PLATFORM_MAX_PATH_LENGTH
Definition common.h:95
unsigned char uint8_t
Definition common.h:60
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
char file_path[4096]
Definition mmap.c:42
Color scheme definition.
Definition colorscheme.h:76
rgb_pixel_t log_colors_light[8]
Definition colorscheme.h:85
char source_file[4096]
Definition colorscheme.h:89
char description[256]
Definition colorscheme.h:78
rgb_pixel_t log_colors_dark[8]
Definition colorscheme.h:81
char name[64]
Definition colorscheme.h:77
bool has_light_variant
Definition colorscheme.h:84
char background_codes[8][32]
terminal_background_t background
Compiled ANSI escape codes for a color scheme.
Definition colorscheme.h:99
const char * codes_16[8]
const char * codes_256[8]
const char * codes_truecolor[8]