27 while (ncap < ob->len + need)
28 ncap = (ncap * 3) / 2;
32 }
else if (ob->
len + need > ob->
cap) {
34 size_t ncap = ob->
cap;
35 while (ncap < ob->len + need)
36 ncap = (ncap * 3) / 2;
91 tmp[i++] =
'0' + (v % 10u);
96 ob->
buf[ob->
len++] = tmp[i];
167 ob_u8(ob, color_idx);
179 ob_u8(ob, color_idx);
#define SAFE_REALLOC(ptr, size, cast)
#define SAFE_MEMCPY(dest, dest_size, src, count)
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)
Dynamic Output Buffer with ANSI Sequence Support.
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)