ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
output_buffer.h
Go to the documentation of this file.
1#pragma once
2
54#include <stdio.h>
55#include <string.h>
56#include <stdbool.h>
57#include <stddef.h>
58#include <stdint.h>
59#include "util/number.h" // For digits_u32()
60
61/* ============================================================================
62 * Data Structures
63 * ============================================================================
64 */
65
84typedef struct {
85 char *buf;
86 size_t len;
87 size_t cap;
88} outbuf_t;
89
90/* ============================================================================
91 * Buffer Management Functions
92 * @{
93 */
94
110void ob_reserve(outbuf_t *ob, size_t need);
111
126void ob_putc(outbuf_t *ob, char c);
127
144void ob_write(outbuf_t *ob, const char *s, size_t n);
145
159void ob_term(outbuf_t *ob);
160
163/* ============================================================================
164 * Integer Formatting Functions
165 * @{
166 */
167
182void ob_u8(outbuf_t *ob, uint8_t v);
183
198void ob_u32(outbuf_t *ob, uint32_t v);
199
202/* ============================================================================
203 * ANSI Escape Sequence Emission Functions
204 * @{
205 */
206
224
242
259void emit_set_256_color_fg(outbuf_t *ob, uint8_t color_idx);
260
277void emit_set_256_color_bg(outbuf_t *ob, uint8_t color_idx);
278
293void emit_reset(outbuf_t *ob);
294
297/* ============================================================================
298 * Run-Length Encoding (RLE) Functions
299 * @{
300 */
301
322bool rep_is_profitable(uint32_t runlen);
323
347void emit_rep(outbuf_t *ob, uint32_t extra);
348
351/* ============================================================================
352 * Auto-Select Color Mode Functions
353 * @{
354 */
355
375void emit_set_fg(outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b);
376
396void emit_set_bg(outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b);
397
400/* ============================================================================
401 * Utility Functions
402 * ============================================================================
403 */
404
405/* digits_u32() is now in util/number.h - include above for access */
unsigned int uint32_t
Definition common.h:58
unsigned char uint8_t
Definition common.h:56
void emit_set_256_color_bg(outbuf_t *ob, uint8_t color_idx)
Emit 256-color background ANSI sequence.
void emit_set_bg(outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b)
Emit background color sequence (auto-select mode)
void ob_u32(outbuf_t *ob, uint32_t v)
Append unsigned 32-bit integer as decimal string.
void ob_u8(outbuf_t *ob, uint8_t v)
Append unsigned 8-bit integer as decimal string.
void emit_set_256_color_fg(outbuf_t *ob, uint8_t color_idx)
Emit 256-color foreground ANSI sequence.
void ob_term(outbuf_t *ob)
Append null terminator to buffer.
void ob_putc(outbuf_t *ob, char c)
Append a character to buffer.
bool rep_is_profitable(uint32_t runlen)
Check if run-length encoding is profitable.
void ob_reserve(outbuf_t *ob, size_t need)
Reserve buffer space for upcoming writes.
void emit_set_truecolor_fg(outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b)
Emit truecolor foreground ANSI sequence.
void emit_rep(outbuf_t *ob, uint32_t extra)
Emit run-length encoded sequence.
void ob_write(outbuf_t *ob, const char *s, size_t n)
Append a string to buffer.
void emit_reset(outbuf_t *ob)
Emit ANSI reset sequence.
void emit_set_truecolor_bg(outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b)
Emit truecolor background ANSI sequence.
void emit_set_fg(outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b)
Emit foreground color sequence (auto-select mode)
🔢 Number Formatting and Conversion Utilities
Dynamic output buffer (auto-expanding)
size_t cap
Buffer capacity in bytes (maximum length before reallocation)
size_t len
Current length in bytes (excluding null terminator)
char * buf
Buffer pointer (allocated, owned by caller, must be freed)