ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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>
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 ===== */
67
68/* ===== RGB Error for Dithering ===== */
69typedef struct {
70 int r;
71 int g;
72 int b;
77
78/* ===== Basic ANSI Utilities ===== */
79
93char *ansi_strip_escapes(const char *input, size_t input_len);
94
106const char *ansi_skip_escape(const char *ptr, const char *end);
107
120bool ansi_is_already_colorized(const char *message, size_t pos);
121
122/* ===== Truecolor Functions ===== */
123
133char *append_truecolor_fg(char *dst, uint8_t r, uint8_t g, uint8_t b);
134
144char *append_truecolor_bg(char *dst, uint8_t r, uint8_t g, uint8_t b);
145
158char *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,
159 uint8_t bg_b);
160
161/* ===== Run-Length Encoding Functions ===== */
162
170void ansi_rle_init(ansi_rle_context_t *ctx, char *buffer, size_t capacity, ansi_color_mode_t mode);
171
180void ansi_rle_add_pixel(ansi_rle_context_t *ctx, uint8_t r, uint8_t g, uint8_t b, char ascii_char);
181
187
188/* ===== Initialization Functions ===== */
189
193void ansi_fast_init(void);
194
198void ansi_fast_init_256color(void);
199
203void ansi_fast_init_16color(void);
204
205/* ===== 256-Color Functions ===== */
206
213char *append_256color_fg(char *dst, uint8_t color_index);
214
221char *append_256color_bg(char *dst, uint8_t color_index);
222
232
235
236/* ===== 16-Color Functions ===== */
237
244char *append_16color_fg(char *dst, uint8_t color_index);
245
252char *append_16color_bg(char *dst, uint8_t color_index);
253
263
271void get_16color_rgb(uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b);
272
285uint8_t rgb_to_16color_dithered(int r, int g, int b, int x, int y, int width, int height, rgb_error_t *error_buffer);
286
287/* ===== Mode-Aware Color Functions ===== */
288
298char *append_color_fg_for_mode(char *dst, uint8_t r, uint8_t g, uint8_t b, terminal_color_mode_t mode);
299
303
304#ifdef __cplusplus
305}
306#endif
307
308#endif // ASCIICHAT_VIDEO_TERMINAL_ANSI_H
⚙️ Common definitions, error codes, macros, and types shared throughout the application
unsigned int height
Definition fft.c:23
unsigned int width
Definition fft.c:23
char * append_16color_fg(char *dst, uint8_t color_index)
Definition ansi.c:322
char * append_16color_bg(char *dst, uint8_t color_index)
Definition ansi.c:338
char * append_256color_bg(char *dst, uint8_t color_index)
Definition ansi.c:243
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:232
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:354
void get_256color_rgb(uint8_t index, uint8_t *r, uint8_t *g, uint8_t *b)
Definition ansi.c:278
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:428
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:227
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:211
void get_16color_rgb(uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b)
Definition ansi.c:397
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:236
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:505
uint8_t rgb_to_256color(uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:251
void ansi_fast_init_16color(void)
Definition ansi.c:315
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
Definition common.h:63
unsigned char uint8_t
Definition common.h:60
🔢 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:8
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:72
int g
Definition ansi.h:71
int r
Definition ansi.h:70
SIMD-optimized ASCII conversion interface.