ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
ansi.h
Go to the documentation of this file.
1
13#ifndef ASCIICHAT_VIDEO_TERMINAL_ANSI_H
14#define ASCIICHAT_VIDEO_TERMINAL_ANSI_H
15
16#include <ascii-chat/common.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/* ===== ANSI Mode Enumeration ===== */
43
44/* ===== Run-Length Encoding Context ===== */
55
56/* ===== ANSI Timing ===== */
61
62/* ===== RGB Error for Dithering ===== */
63typedef struct {
64 int r;
65 int g;
66 int b;
68
69/* ===== Basic ANSI Utilities ===== */
70
83char *ansi_strip_escapes(const char *input, size_t input_len);
84
96const char *ansi_skip_escape(const char *ptr, const char *end);
97
110bool ansi_is_already_colorized(const char *message, size_t pos);
111
112/* ===== Truecolor Functions ===== */
113
123char *append_truecolor_fg(char *dst, uint8_t r, uint8_t g, uint8_t b);
124
134char *append_truecolor_bg(char *dst, uint8_t r, uint8_t g, uint8_t b);
135
148char *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,
149 uint8_t bg_b);
150
151/* ===== Run-Length Encoding Functions ===== */
152
160void ansi_rle_init(ansi_rle_context_t *ctx, char *buffer, size_t capacity, ansi_color_mode_t mode);
161
170void ansi_rle_add_pixel(ansi_rle_context_t *ctx, uint8_t r, uint8_t g, uint8_t b, char ascii_char);
171
177
178/* ===== Initialization Functions ===== */
179
183void ansi_fast_init(void);
184
188void ansi_fast_init_256color(void);
189
193void ansi_fast_init_16color(void);
194
195/* ===== 256-Color Functions ===== */
196
203char *append_256color_fg(char *dst, uint8_t color_index);
204
211char *append_256color_bg(char *dst, uint8_t color_index);
212
222
223/* ===== 16-Color Functions ===== */
224
231char *append_16color_fg(char *dst, uint8_t color_index);
232
239char *append_16color_bg(char *dst, uint8_t color_index);
240
250
258void get_16color_rgb(uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b);
259
272uint8_t rgb_to_16color_dithered(int r, int g, int b, int x, int y, int width, int height, rgb_error_t *error_buffer);
273
274/* ===== Mode-Aware Color Functions ===== */
275
286
291#ifdef __cplusplus
292}
293#endif
294
295#endif // ASCIICHAT_VIDEO_TERMINAL_ANSI_H
⚙️ Common definitions, error codes, macros, and types shared throughout the application
char * append_16color_fg(char *dst, uint8_t color_index)
Definition ansi.c:405
char * append_16color_bg(char *dst, uint8_t color_index)
Definition ansi.c:421
char * append_256color_bg(char *dst, uint8_t color_index)
Definition ansi.c:352
char * append_truecolor_fg(char *dst, uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:143
void ansi_fast_init_256color(void)
Definition ansi.c:334
const char * ansi_skip_escape(const char *ptr, const char *end)
Find the end of an ANSI CSI escape sequence.
Definition ansi.c:74
uint8_t rgb_to_16color(uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:437
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:511
ansi_color_mode_t
Definition ansi.h:38
void ansi_rle_init(ansi_rle_context_t *ctx, char *buffer, size_t capacity, ansi_color_mode_t mode)
Definition ansi.c:248
char * ansi_strip_escapes(const char *input, size_t input_len)
Strip all ANSI escape sequences from a string.
Definition ansi.c:23
void ansi_fast_init(void)
Definition ansi.c:319
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:199
void ansi_rle_finish(ansi_rle_context_t *ctx)
Definition ansi.c:303
void get_16color_rgb(uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b)
Definition ansi.c:480
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:261
bool ansi_is_already_colorized(const char *message, size_t pos)
Check if a position in text is already colored.
Definition ansi.c:98
char * append_256color_fg(char *dst, uint8_t color_index)
Definition ansi.c:344
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:588
uint8_t rgb_to_256color(uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:360
void ansi_fast_init_16color(void)
Definition ansi.c:398
char * append_truecolor_bg(char *dst, uint8_t r, uint8_t g, uint8_t b)
Definition ansi.c:173
@ ANSI_MODE_FOREGROUND_BACKGROUND
Definition ansi.h:41
@ ANSI_MODE_FOREGROUND
Definition ansi.h:39
@ ANSI_MODE_BACKGROUND
Definition ansi.h:40
unsigned long long uint64_t
Definition common.h:59
unsigned char uint8_t
Definition common.h:56
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
Platform initialization and static synchronization helpers.
Lock-free module lifecycle state machine using pure stdatomic.
🔢 Mathematical Utility Functions
ClangTool/LibTooling compatibility shim for stdbool.h.
uint8_t last_b
Definition ansi.h:53
uint8_t last_g
Definition ansi.h:52
size_t capacity
Definition ansi.h:47
uint8_t last_r
Definition ansi.h:51
char * buffer
Definition ansi.h:46
bool first_pixel
Definition ansi.h:50
size_t length
Definition ansi.h:48
ansi_color_mode_t mode
Definition ansi.h:49
uint64_t end_ns
Definition ansi.h:59
uint64_t start_ns
Definition ansi.h:58
int b
Definition ansi.h:66
int g
Definition ansi.h:65
int r
Definition ansi.h:64
terminal_color_mode_t
Terminal color support levels.
Definition terminal.h:578
SIMD-optimized ASCII conversion interface.