ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
output_buffer.h File Reference

Go to the source code of this file.

Data Structures

struct  outbuf_t
 Dynamic output buffer (auto-expanding). More...

Functions

void ob_reserve (outbuf_t *ob, size_t need)
 Dynamic output buffer (auto-expanding).
void ob_putc (outbuf_t *ob, char c)
 Append a character to buffer.
void ob_write (outbuf_t *ob, const void *s, size_t n)
 Append a string to buffer.
void ob_term (outbuf_t *ob)
 Append null terminator to buffer.
void ob_u8 (outbuf_t *ob, uint8_t v)
 Append unsigned 8-bit integer as decimal string.
void ob_u32 (outbuf_t *ob, uint32_t v)
 Append unsigned 32-bit integer as decimal string.
void emit_set_truecolor_fg (outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b)
 Emit truecolor foreground ANSI 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_256_color_fg (outbuf_t *ob, uint8_t color_idx)
 Emit 256-color foreground ANSI sequence.
void emit_set_256_color_bg (outbuf_t *ob, uint8_t color_idx)
 Emit 256-color background ANSI sequence.
void emit_reset (outbuf_t *ob)
 Emit ANSI reset sequence.
bool rep_is_profitable (uint32_t runlen)
 Check if run-length encoding is profitable.
void emit_rep (outbuf_t *ob, uint32_t extra)
 Emit run-length encoded sequence.
void emit_set_fg (outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b)
 Emit foreground color sequence (auto-select mode).
void emit_set_bg (outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b)
 Emit background color sequence (auto-select mode).
void emit_glyph_run (outbuf_t *out, const void *glyph, size_t bytes, uint32_t count)
void emit_row_end (outbuf_t *out, bool colored, bool newline)

Function Documentation

◆ emit_glyph_run()

void emit_glyph_run ( outbuf_t * out,
const void * glyph,
size_t bytes,
uint32_t count )

Emit complete UTF-8 glyphs, using REP only when it saves bytes. count includes the first glyph; callers keep runs inside one terminal row.

Definition at line 183 of file output_buffer.c.

183 {
184 if (!count || !bytes)
185 return;
186 ob_write(out, glyph, bytes);
187 uint32_t extra = count - 1;
188 // Compare division rather than multiplying count by glyph size (overflow).
189 size_t cost = digits_u32(extra) + 3u;
190 if (extra > cost / bytes) {
191 emit_rep(out, extra);
192 } else {
193 for (uint32_t i = 0; i < extra; ++i)
194 ob_write(out, glyph, bytes);
195 }
196}
unsigned int uint32_t
Definition common.h:62
void emit_rep(outbuf_t *ob, uint32_t extra)
Emit run-length encoded sequence.
void ob_write(outbuf_t *ob, const void *s, size_t n)
Append a string to buffer.
static bool size_t gotel_query_t * out
Definition queries.h:8

References emit_rep(), ob_write(), and out.

◆ emit_row_end()

void emit_row_end ( outbuf_t * out,
bool colored,
bool newline )

Reset colored state before moving to the next row.

Definition at line 198 of file output_buffer.c.

198 {
199 if (colored)
201 if (newline)
202 ob_putc(out, '\n');
203}
void ob_putc(outbuf_t *ob, char c)
Append a character to buffer.
void emit_reset(outbuf_t *out)
Emit ANSI reset sequence.

References emit_reset(), ob_putc(), and out.

Referenced by ascii_frame_emit_halfrow(), ascii_frame_emit_row(), and ascii_render_glyph_match_mode().