ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
ansi.h
Go to the documentation of this file.
1
12
13#ifndef ASCIICHAT_VIDEO_TERMINAL_ANSI_H
14#define ASCIICHAT_VIDEO_TERMINAL_ANSI_H
15
16#include <ascii-chat/common.h>
17#include <libplatform/lifecycle.h>
21#include <options/options.h>
22#include <stddef.h>
23#include <stdint.h>
24#include <stdbool.h>
25
26#define ANSI_RESET "\033[0m"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
37
38/* ===== ANSI Mode Enumeration ===== */
44
45/* ===== Run-Length Encoding Context ===== */
58
59/* ===== ANSI Timing ===== */
69
70/* ===== RGB Error for Dithering ===== */
71typedef struct {
72 int r;
73 int g;
74 int b;
81
82/* ===== Basic ANSI Utilities ===== */
83
99char *ansi_strip_escapes(const char *input, size_t input_len);
100
112const char *ansi_skip_escape(const char *ptr, const char *end);
113
126bool ansi_is_already_colorized(const char *message, size_t pos);
127
128/* ===== Truecolor Functions ===== */
129
139char *append_truecolor_fg(char *dst, uint8_t r, uint8_t g, uint8_t b);
140
150char *append_truecolor_bg(char *dst, uint8_t r, uint8_t g, uint8_t b);
151
164char *append_truecolor_fg_bg(char *dst, uint8_t fg_r, uint8_t fg_g, uint8_t fg_b, uint8_t bg_r, uint8_t bg_g, uint8_t bg_b);
165
166/* ===== Run-Length Encoding Functions ===== */
167
175void ansi_rle_init(ansi_rle_context_t *ctx, char *buffer, size_t capacity, ansi_color_mode_t mode);
176
185void ansi_rle_add_pixel(ansi_rle_context_t *ctx, uint8_t r, uint8_t g, uint8_t b, char ascii_char);
186
192
193/* ===== Initialization Functions ===== */
194
198void ansi_fast_init(void);
199
203void ansi_fast_init_256color(void);
204
208void ansi_fast_init_16color(void);
209
210/* ===== 256-Color Functions ===== */
211
218char *append_256color_fg(char *dst, uint8_t color_index);
219
226char *append_256color_bg(char *dst, uint8_t color_index);
227
237
240
241/* ===== 16-Color Functions ===== */
242
249char *append_16color_fg(char *dst, uint8_t color_index);
250
257char *append_16color_bg(char *dst, uint8_t color_index);
258
268
276void get_16color_rgb(uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b);
277
290uint8_t rgb_to_16color_dithered(int r, int g, int b, int x, int y, int width, int height, rgb_error_t *error_buffer);
291
292/* ===== Mode-Aware Color Functions ===== */
293
303char *append_color_fg_for_mode(char *dst, uint8_t r, uint8_t g, uint8_t b, terminal_color_mode_t mode);
304
308
309#ifdef __cplusplus
310}
311#endif
312
313#endif // ASCIICHAT_VIDEO_TERMINAL_ANSI_H
Platform initialization and static synchronization helpers.
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24
char * append_16color_fg(char *dst, uint8_t color_index)
Definition ansi.c:321
char * append_16color_bg(char *dst, uint8_t color_index)
Definition ansi.c:337
char * append_256color_bg(char *dst, uint8_t color_index)
Definition ansi.c:242
char * append_truecolor_fg(char *dst, uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:141
void ansi_fast_init_256color(void)
Definition ansi.c:231
const char * ansi_skip_escape(const char *ptr, const char *end)
Find the end of an ANSI CSI escape sequence.
Definition ansi.c:78
uint8_t rgb_to_16color(uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:353
void get_256color_rgb(uint8_t index, uint8_t *r, uint8_t *g, uint8_t *b)
Definition ansi.c:277
uint8_t rgb_to_16color_dithered(int r, int g, int b, int x, int y, int width, int height, rgb_error_t *error_buffer)
Definition ansi.c:427
ansi_color_mode_t
Definition ansi.h:39
void ansi_rle_init(ansi_rle_context_t *ctx, char *buffer, size_t capacity, ansi_color_mode_t mode)
Definition ansi.c:156
char * ansi_strip_escapes(const char *input, size_t input_len)
When code needs to work with rgb error, it keeps r, g, b here instead of scattering it across globals...
Definition ansi.c:27
void ansi_fast_init(void)
Definition ansi.c:226
char * append_truecolor_fg_bg(char *dst, uint8_t fg_r, uint8_t fg_g, uint8_t fg_b, uint8_t bg_r, uint8_t bg_g, uint8_t bg_b)
Definition ansi.c:149
void ansi_rle_finish(ansi_rle_context_t *ctx)
Definition ansi.c:210
void get_16color_rgb(uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b)
Definition ansi.c:396
void ansi_rle_add_pixel(ansi_rle_context_t *ctx, uint8_t r, uint8_t g, uint8_t b, char ascii_char)
Definition ansi.c:169
bool ansi_is_already_colorized(const char *message, size_t pos)
Check if a position in text is already colored.
Definition ansi.c:102
char * append_256color_fg(char *dst, uint8_t color_index)
Definition ansi.c:235
char * append_color_fg_for_mode(char *dst, uint8_t r, uint8_t g, uint8_t b, terminal_color_mode_t mode)
Definition ansi.c:504
uint8_t rgb_to_256color(uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:250
void ansi_fast_init_16color(void)
Definition ansi.c:314
char * append_truecolor_bg(char *dst, uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:145
@ ANSI_MODE_FOREGROUND_BACKGROUND
Definition ansi.h:42
@ ANSI_MODE_FOREGROUND
Definition ansi.h:40
@ ANSI_MODE_BACKGROUND
Definition ansi.h:41
unsigned long long uint64_t
unsigned char uint8_t
⚙️ Common definitions, error codes, macros, and types shared throughout the application
SIMD-optimized ASCII conversion interface.
🔢 Mathematical Utility Functions
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
static bool size_t index
Definition queries.h:10
uint8_t last_b
Definition ansi.h:54
uint8_t last_g
Definition ansi.h:53
size_t capacity
Definition ansi.h:48
uint8_t last_r
Definition ansi.h:52
char * buffer
Definition ansi.h:47
bool first_pixel
Definition ansi.h:51
size_t length
Definition ansi.h:49
ansi_color_mode_t mode
Definition ansi.h:50
uint64_t end_ns
Definition ansi.h:62
uint64_t start_ns
Definition ansi.h:61
int b
Definition ansi.h:74
int g
Definition ansi.h:73
int r
Definition ansi.h:72