ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
error_popup.c
Go to the documentation of this file.
1
2/* Storage capacities in elements; text buffers include the terminating NUL. */
3#define TUI_ERROR_POPUP_WRAPPED_BUFFER_SIZE 65536
4#define TUI_ERROR_POPUP_STYLE_BUFFER_SIZE 128
5#define TUI_ERROR_POPUP_THREAD_BUFFER_SIZE 160
6#define TUI_ERROR_POPUP_FILE_BUFFER_SIZE 1024
7#define TUI_ERROR_POPUP_FUNCTION_BUFFER_SIZE 256
8#define TUI_ERROR_POPUP_LINE_BUFFER_SIZE 24
9#define TUI_ERROR_POPUP_ADDRESS_BUFFER_SIZE 40
10#define TUI_ERROR_POPUP_TITLE_BUFFER_SIZE 128
11#define TUI_ERROR_POPUP_HEADING_BUFFER_SIZE 256
12#define TUI_ERROR_POPUP_CODE_BUFFER_SIZE 512
13#define TUI_ERROR_POPUP_CELL_BUFFER_SIZE 1024
14#define TUI_ERROR_POPUP_FINAL_OUTPUT_BUFFER_SIZE 65536
15
16/* Existing buffer budgets in bytes, including NUL for text storage. */
17#define ERROR_POPUP_LINE_CAPACITY 2048
18
21#include <ascii-chat/log/io.h>
22#include <ascii-chat/otel.h>
23#include <ascii-chat/source_root.h>
29#include <ascii-chat/ui/popup.h>
31#include <ascii-chat/ui/text.h>
35#include <libplatform/compiler.h>
36#include <libplatform/system.h>
37#include <libplatform/terminal.h>
38#include <options/options.h>
39#include <stdatomic.h>
40#include <string.h>
41
42// Only short value copies and navigation run under this guard, never rendering
43// or symbolization.
44static atomic_flag g_guard = ATOMIC_FLAG_INIT;
46static size_t g_count, g_selected, g_scroll, g_body_rows = 1, g_page_rows = 1;
47static uint64_t g_latest, g_displayed_latest, g_dropped;
48
49static void lock_state(void) {
50 while (atomic_flag_test_and_set_explicit(&g_guard, memory_order_acquire)) {
51 }
52}
53static void unlock_state(void) {
54 atomic_flag_clear_explicit(&g_guard, memory_order_release);
55}
56
57static void refresh_locked(void) {
58 uint64_t selected_id = g_count ? g_entries[g_selected].error_id : 0;
60 g_entries, ASCIICHAT_ERRNO_HISTORY_SIZE, &g_dropped);
61 uint64_t latest = g_count ? g_entries[g_count - 1].error_id : 0;
62 if (latest != g_latest) {
63 g_selected = g_count ? g_count - 1 : 0;
64 g_scroll = 0;
65 g_latest = latest;
66 } else {
67 g_selected = 0;
68 for (size_t i = 0; i < g_count; ++i)
69 if (g_entries[i].error_id == selected_id)
70 g_selected = i;
71 }
72}
73
75
77 lock_state();
78 refresh_locked();
79 uint64_t revision = g_latest;
80 unlock_state();
81 return revision;
82}
83
84terminal_size_t ui_error_popup_minimum(void) {
85 return (terminal_size_t){.cols = 60, .rows = 14};
86}
87
88void ui_error_popup_key(keyboard_key_t key) {
89 lock_state();
90 refresh_locked();
91 uint64_t dismiss = 0;
92 size_t previous = g_selected;
93 size_t previous_scroll = g_scroll;
94 switch ((int)key) {
95 case KEY_ESCAPE:
96 case 'q':
97 case '\r':
98 case '\n':
99 /* Dismiss all notifications currently shown. The popup may receive the
100 * first key before its presentation-thread snapshot has been rendered. */
101 dismiss = UINT64_MAX;
102 break;
103 case KEY_LEFT:
104 if (g_selected)
105 --g_selected;
106 break;
107 case KEY_RIGHT:
108 if (g_selected + 1 < g_count)
109 ++g_selected;
110 break;
111 case KEY_HOME:
112 g_selected = 0;
113 break;
114 case KEY_END:
115 g_selected = g_count ? g_count - 1 : 0;
116 break;
117 case KEY_UP:
118 if (g_scroll)
119 --g_scroll;
120 break;
121 case KEY_DOWN:
122 ++g_scroll;
123 break;
124 case KEY_PAGEUP:
125 g_scroll = g_scroll > g_page_rows ? g_scroll - g_page_rows : 0;
126 break;
127 case KEY_PAGEDOWN:
128 g_scroll += g_page_rows;
129 break;
130 default:
131 break;
132 }
133 if (g_selected != previous)
134 g_scroll = 0;
135 size_t maximum = g_body_rows > g_page_rows ? g_body_rows - g_page_rows : 0;
136 if (g_scroll > maximum)
137 g_scroll = maximum;
138 bool selection_changed = previous != g_selected;
139 bool scrolled = previous_scroll != g_scroll && !selection_changed;
140 unlock_state();
141 if (selection_changed)
142 ascii_otel_ui_usage("error", "selected", 0);
143 if (scrolled)
144 ascii_otel_ui_usage("error", "details_scrolled", 0);
145 if (dismiss)
146 ascii_otel_ui_usage("error", "dismissed", 0);
147 if (dismiss)
150}
151
152// These caches belong exclusively to the presentation thread. Raw backtraces
153// are copied, symbolized once per selection, then freed; notification snapshots
154// never own symbols.
155static uint64_t g_cached_id;
156static int g_cached_width;
157static bool g_cached_color;
158static char g_wrapped[TUI_ERROR_POPUP_WRAPPED_BUFFER_SIZE];
159static size_t g_lines[ERROR_POPUP_LINE_CAPACITY], g_line_count, g_trace_start;
160#ifdef ASCIICHAT_DIAGNOSTIC_UI
161static backtrace_text_t g_trace;
162#endif
163
164static void sanitize(char *out, size_t capacity, const char *text) {
165 size_t used = 0;
166 for (const unsigned char *p = (const unsigned char *)(text ? text : "");
167 *p && used + 1 < capacity; ++p) {
168 // Messages may contain paths or remote text. Never interpret terminal
169 // controls from them.
170 unsigned char c = *p;
171 if (c == 0xc2 && p[1] >= 0x80 && p[1] <= 0x9f) {
172 out[used++] = '?';
173 ++p;
174 continue;
175 }
176 if (c == '\t')
177 c = ' ';
178 else if ((c < 32 && c != '\n') || c == 127)
179 c = '?';
180 out[used++] = (char)c;
181 }
182 out[used] = '\0';
183}
184
185static void append_bytes(size_t *used, const char *text, size_t bytes) {
186 bytes = MIN(bytes, sizeof(g_wrapped) - 1 - *used);
187 memcpy(g_wrapped + *used, text, bytes);
188 *used += bytes;
189 g_wrapped[*used] = '\0';
190}
191
192static void wrap_body(const char *text, int width) {
193 size_t used = 0;
194 int cells = 0;
195 char style[TUI_ERROR_POPUP_STYLE_BUFFER_SIZE] = "";
196 g_line_count = 1;
197 g_lines[0] = 0;
198 g_wrapped[0] = '\0';
199 while (*text && used + 256 < sizeof(g_wrapped) &&
200 g_line_count < ARRAY_SIZE(g_lines)) {
201 if (text[0] == '\033' && text[1] == '[') {
202 const char *end = text + 2;
203 while (*end && !(*end >= '@' && *end <= '~'))
204 ++end;
205 if (*end != 'm') {
206 // The formatter supplies SGR only. Ignore any unexpected control
207 // sequence.
208 text = *end ? end + 1 : end;
209 continue;
210 }
211 size_t bytes = (size_t)(end + 1 - text);
212 append_bytes(&used, text, bytes);
213 if (bytes < sizeof(style)) {
214 memcpy(style, text, bytes);
215 style[bytes] = '\0';
216 }
217 text = end + 1;
218 continue;
219 }
220 int bytes = utf8_next_char_bytes(text, strlen(text));
221 if (bytes <= 0)
222 bytes = 1;
223 int columns = utf8_display_width_n(text, (size_t)bytes);
224 if (*text == '\n' || (cells && cells + columns > width)) {
225 if (style[0])
226 append_bytes(&used, "\033[0m", 4);
227 g_lines[g_line_count++] = used + 1;
228 append_bytes(&used, "\n", 1);
229 append_bytes(&used, style, strlen(style));
230 cells = 0;
231 if (*text == '\n')
232 ++text;
233 continue;
234 }
235 append_bytes(&used, text, (size_t)bytes);
236 cells += MAX(columns, 0);
237 text += bytes;
238 }
239}
240
241static void build_body(const asciichat_error_context_t *error, int width,
242 bool colors) {
243 g_trace_start = 0;
244 char message[ASCIICHAT_ERRNO_MESSAGE_MAX],
249 sanitize(message, sizeof(message), error->context_message);
250 named_metadata_t metadata = {0};
251 bool named = named_metadata_copy((uintptr_t)error->thread_id, &metadata) &&
252 metadata.name[0];
253 if (named)
254 sanitize(thread, sizeof(thread), metadata.name);
255 else
256 safe_snprintf(thread, sizeof(thread), "0x%llx",
257 (unsigned long long)error->thread_id);
259 if (!body) {
260 wrap_body("Error details unavailable (out of memory)", width);
261 return;
262 }
263 const char *grey = colors ? ui_text_color_prefix(LOG_COLOR_GREY) : "";
264 const char *reset = colors ? "\033[0m" : "";
266 body, "Details: %s%s\n\n%sThread: %s",
267 message[0] ? message : "No additional details",
268 error->message_truncated ? " [truncated]" : "", grey,
270 : thread);
271 if (named) {
273 safe_snprintf(address, sizeof(address), "0x%llx",
274 (unsigned long long)error->thread_id);
275 frame_buffer_printf(body, " (%s)",
277 : address);
278 }
279 frame_buffer_printf(body, "%s\n", reset);
280 if (error->has_system_error)
281 frame_buffer_printf(body, "System error: %d (%s)\n", error->system_errno,
283 if (error->has_wsa_error)
284 frame_buffer_printf(body, "Socket error: %d\n", error->wsa_error);
285#ifdef ASCIICHAT_DIAGNOSTIC_UI
286 sanitize(file, sizeof(file),
288 error->file, ASCIICHAT_OWNED_SOURCE_DIRS)
289 : "?");
290 sanitize(function, sizeof(function), error->function);
291 safe_snprintf(line, sizeof(line), "%d", error->line);
293 body, "%sSource: %s %s:%s%s\n", grey,
294 colors ? colored_string(LOG_COLOR_DEBUG, file) : file,
295 colors ? colored_string(LOG_COLOR_DEV, function) : function,
296 colors ? colored_string(LOG_COLOR_GREY, line) : line, reset);
297 if (g_cached_id != error->error_id) {
298 memset(&g_trace, 0, sizeof(g_trace));
299 backtrace_t trace = error->backtrace;
300 trace.symbols = NULL;
301 trace.tried_symbolize = false;
302 if (trace.count) {
303 LOG_IO("symbolizer",
304 { backtrace_symbolize(&trace, ASCIICHAT_OWNED_SOURCE_DIRS); });
305 if (trace.symbols)
306 backtrace_format_styled(&g_trace, "Backtrace", &trace,
307 ERROR_BACKTRACE_INTERNAL_FRAMES, 0,
309 backtrace_t_free(&trace);
310 }
311 }
312 wrap_body(frame_buffer_get_content(body), width);
313 if (g_trace.plain[0])
314 g_trace_start = g_line_count + 1;
315 const char *trace_text = g_trace.plain[0]
316 ? (colors ? g_trace.colored : g_trace.plain)
317 : "Backtrace unavailable";
318 size_t trace_length = strlen(trace_text);
319 if (trace_length && trace_text[trace_length - 1] == '\n')
320 --trace_length;
321 frame_buffer_printf(body, "\n%.*s", (int)trace_length, trace_text);
322#else
323 (void)file;
324 (void)function;
325 (void)line;
326#endif
327 wrap_body(frame_buffer_get_content(body), width);
329 g_cached_id = error->error_id;
330 g_cached_width = width;
331 g_cached_color = colors;
332}
333
334static void format_error_heading(char *buffer, size_t capacity,
335 const asciichat_error_context_t *error) {
336 safe_snprintf(buffer, capacity, "%s (%d): %s",
337 asciichat_error_name(error->code), error->code,
338 asciichat_error_string(error->code));
339}
340
341void ui_error_popup_render(frame_buffer_t *out, terminal_size_t size) {
342 asciichat_error_context_t error = {0};
343 lock_state();
344 refresh_locked();
345 size_t count = g_count, selected = g_selected;
346 uint64_t displayed_latest = g_latest, dropped = g_dropped;
347 if (count)
348 error = g_entries[selected];
349 unlock_state();
350 if (!count)
351 return;
352 terminal_size_t minimum = ui_error_popup_minimum();
353 frame_buffer_append(out, "\033[0m\033[?25l", 10);
354 if (ui_too_small(size, minimum)) {
355 ui_too_small_render(out, size, minimum);
356 return;
357 }
358 lock_state();
359 g_displayed_latest = displayed_latest;
360 unlock_state();
361 bool colors =
362 !GET_OPTION(strip_ansi) &&
365 int width = MIN(size.cols - 4, 100);
366 int body_width = width - 6;
367 if (g_cached_id != error.error_id || g_cached_width != body_width ||
368 g_cached_color != colors)
369 build_body(&error, body_width, colors);
370 size_t desired_rows =
371 g_trace_start ? MIN(g_line_count, g_trace_start + 12) : g_line_count;
372 int body_rows = MIN(size.rows - 8, MIN(22, (int)desired_rows));
373 size_t fixed_rows =
374 g_trace_start && g_trace_start < (size_t)body_rows ? g_trace_start : 0;
375 if (g_trace_start && !fixed_rows)
376 body_rows = MIN(body_rows, 12);
377 int height = body_rows + 6;
378 int top = (size.rows - height) / 2 + 1, left = (size.cols - width) / 2 + 1;
379 size_t scroll_rows = g_line_count - fixed_rows;
380 size_t page_rows = (size_t)body_rows - fixed_rows;
381 lock_state();
382 g_body_rows = scroll_rows;
383 g_page_rows = page_rows;
384 size_t maximum = scroll_rows > page_rows ? scroll_rows - page_rows : 0;
385 g_scroll = MIN(g_scroll, maximum);
386 size_t scroll = g_scroll;
387 unlock_state();
390 safe_snprintf(title, sizeof(title), "Error (%zu) %zu of %zu%s", count,
391 selected + 1, count, dropped ? " [older errors dropped]" : "");
393 ui_text_cell(heading, sizeof(heading), title, width - 4, UI_ALIGN_LEFT);
394 frame_buffer_printf(out, "\033[%d;%dH%s", top + 1, left + 2,
396 : heading);
399 format_error_heading(code, sizeof(code), &error);
400 ui_text_cell(cell, sizeof(cell), code, width - 4, UI_ALIGN_LEFT);
401 frame_buffer_printf(out, "\033[%d;%dH%s", top + 2, left + 2, cell);
402 for (int i = 0; i < body_rows; ++i) {
403 size_t index = (size_t)i < fixed_rows ? (size_t)i : (size_t)i + scroll;
404 if (index >= g_line_count)
405 break;
406 const char *start = g_wrapped + g_lines[index];
407 const char *end = strchr(start, '\n');
408 frame_buffer_printf(out, "\033[%d;%dH%.*s\033[0m", top + 4 + i, left + 2,
409 (int)(end ? end - start : (ptrdiff_t)strlen(start)),
410 start);
411 }
412 ui_scrollbar_render(out, top + 4 + (int)fixed_rows, left + width - 3,
413 (int)page_rows, scroll_rows, page_rows, scroll);
414 const char *orange = colors ? ui_text_color_prefix(LOG_COLOR_DEV) : "";
415 const char *reset = colors ? "\033[0m" : "";
416 frame_buffer_printf(out, "\033[%d;%dH%s?%s Help", top + height - 2, left + 2,
417 orange, reset);
418 ui_button_t button = {.label = "Dismiss all", .shortcut = '\r'};
419 ui_buttons_render(out, top + height - 2, left + 10, width - 20, &button, 1,
420 0);
421}
422
424 lock_state();
425 g_count = g_selected = g_scroll = 0;
426 g_latest = g_displayed_latest = g_dropped = 0;
427 unlock_state();
428 g_cached_id = 0;
429}
430
431static char g_final_output[TUI_ERROR_POPUP_FINAL_OUTPUT_BUFFER_SIZE];
432static size_t g_final_length;
433static int g_final_fd;
434
435void ui_error_popup_preserve(int fd, terminal_size_t size) {
437 return;
439 size_t count =
440 errno_notifications_snapshot(entries, ARRAY_SIZE(entries), NULL);
441 if (!count)
442 return;
443 bool previous = errno_notifications_suppress(true);
444 frame_buffer_t *output = frame_buffer_create(0, 0);
445 if (output) {
446 bool colors = !GET_OPTION(strip_ansi) &&
448 bool unicode = terminal_should_use_utf8(GET_OPTION(force_utf8));
449 int width = MIN(size.cols > 0 ? size.cols - 1 : 79, 100);
450 width = MAX(width, 8);
451 int body_width = width - 4;
452 size_t first = count > 4 ? count - 4 : 0;
453 frame_buffer_append(output, "\033[0m\033[?25h\r\n", 12);
454 if (first)
456 output, "%zu pending notifications; showing the latest 4.\n", count);
457 for (size_t i = first; i < count; ++i) {
460 const char *side = unicode ? "│" : "|";
461 ui_popup_rule(output, width, UI_POPUP_TOP, false, unicode,
463 frame_buffer_append(output, "\n", 1);
464 ui_text_cell(cell, sizeof(cell), "ERROR", body_width, UI_ALIGN_LEFT);
465 frame_buffer_printf(output, "%s %s %s\n", side,
466 colors ? colored_string(LOG_COLOR_ERROR, cell) : cell,
467 side);
468 format_error_heading(code, sizeof(code), &entries[i]);
469 ui_text_cell(cell, sizeof(cell), code, body_width, UI_ALIGN_LEFT);
470 frame_buffer_printf(output, "%s %s %s\n", side, cell, side);
471 build_body(&entries[i], body_width, colors);
472 for (size_t line = 0; line < g_line_count; ++line) {
473 const char *start = g_wrapped + g_lines[line];
474 const char *end = strchr(start, '\n');
476 size_t length = end ? (size_t)(end - start) : strlen(start);
477 length = MIN(length, sizeof(line_text) - 1);
478 memcpy(line_text, start, length);
479 line_text[length] = '\0';
480 ui_text_cell(cell, sizeof(cell), line_text, body_width, UI_ALIGN_LEFT);
481 frame_buffer_printf(output, "%s %s%s %s\n", side, cell,
482 colors ? "\033[0m" : "", side);
483 }
484 ui_popup_rule(output, width, UI_POPUP_BOTTOM, false, unicode,
486 frame_buffer_append(output, "\n", 1);
487 }
488 if (frame_buffer_get_length(output) <= sizeof(g_final_output)) {
489 g_final_length = frame_buffer_get_length(output);
490 memcpy(g_final_output, frame_buffer_get_content(output), g_final_length);
491 g_final_fd = fd;
492 } else {
493 char message[ASCIICHAT_ERRNO_MESSAGE_MAX];
494 sanitize(message, sizeof(message), entries[count - 1].context_message);
495 int length = safe_snprintf(
496 g_final_output, sizeof(g_final_output),
497 "\nERROR\n%s (%d): %s\nDetails: %s\n",
498 asciichat_error_name(entries[count - 1].code),
499 entries[count - 1].code,
500 asciichat_error_string(entries[count - 1].code), message);
501 g_final_length =
502 length > 0 ? MIN((size_t)length, sizeof(g_final_output) - 1) : 0;
503 g_final_fd = fd;
504 }
505 }
506 if (output)
507 frame_buffer_destroy(output);
509}
510
512 if (g_final_length)
513 platform_write_all(g_final_fd, g_final_output, g_final_length);
514 g_final_length = 0;
515}
void errno_notifications_dismiss(uint64_t through_id)
bool errno_notifications_pending(void)
size_t errno_notifications_snapshot(asciichat_error_context_t *out, size_t capacity, uint64_t *dropped)
bool errno_notifications_suppress(bool suppress)
#define ASCIICHAT_ERRNO_MESSAGE_MAX
#define ASCIICHAT_ERRNO_HISTORY_SIZE
void backtrace_t_free(backtrace_t *bt)
Definition backtrace.c:35
void backtrace_symbolize(backtrace_t *bt, const char *const *owned_dirs)
Definition backtrace.c:42
bool backtrace_filter_error_internal(const char *frame)
Definition backtrace.c:9
void ui_buttons_render(frame_buffer_t *out, int row, int left, int width, const ui_button_t *b, size_t n, size_t selected)
Definition buttons.c:30
@ LOG_COLOR_RESET
Definition color.h:14
@ LOG_COLOR_GREY
Definition color.h:13
@ LOG_COLOR_FATAL
Definition color.h:12
@ LOG_COLOR_ERROR
Definition color.h:11
@ LOG_COLOR_DEV
Definition color.h:7
@ LOG_COLOR_DEBUG
Definition color.h:8
@ LOG_COLOR_WARN
Definition color.h:10
Named object registry for debugging — log identifiable resource names.
#define ERROR_POPUP_LINE_CAPACITY
Definition error_popup.c:17
#define TUI_ERROR_POPUP_FUNCTION_BUFFER_SIZE
Definition error_popup.c:7
bool ui_error_popup_visible(void)
Definition error_popup.c:74
#define TUI_ERROR_POPUP_WRAPPED_BUFFER_SIZE
Definition error_popup.c:3
#define TUI_ERROR_POPUP_FILE_BUFFER_SIZE
Definition error_popup.c:6
#define TUI_ERROR_POPUP_ADDRESS_BUFFER_SIZE
Definition error_popup.c:9
#define TUI_ERROR_POPUP_STYLE_BUFFER_SIZE
Definition error_popup.c:4
#define TUI_ERROR_POPUP_FINAL_OUTPUT_BUFFER_SIZE
Definition error_popup.c:14
void ui_error_popup_key(keyboard_key_t key)
Definition error_popup.c:88
#define TUI_ERROR_POPUP_THREAD_BUFFER_SIZE
Definition error_popup.c:5
#define TUI_ERROR_POPUP_HEADING_BUFFER_SIZE
Definition error_popup.c:11
#define TUI_ERROR_POPUP_CELL_BUFFER_SIZE
Definition error_popup.c:13
void ui_error_popup_preserve(int fd, terminal_size_t size)
void ui_error_popup_flush(void)
uint64_t ui_error_popup_revision(void)
Definition error_popup.c:76
#define TUI_ERROR_POPUP_CODE_BUFFER_SIZE
Definition error_popup.c:12
void ui_error_popup_reset(void)
void ui_error_popup_render(frame_buffer_t *out, terminal_size_t size)
#define TUI_ERROR_POPUP_TITLE_BUFFER_SIZE
Definition error_popup.c:10
#define TUI_ERROR_POPUP_LINE_BUFFER_SIZE
Definition error_popup.c:8
terminal_size_t ui_error_popup_minimum(void)
Definition error_popup.c:84
char cells[(512 *256 *2)]
Definition fft.c:22
unsigned char colors[(512 *256 *2) *3]
Definition fft.c:23
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24
void frame_buffer_append(frame_buffer_t *buf, const char *str, size_t len)
Append raw bytes to the buffer.
void frame_buffer_destroy(frame_buffer_t *buf)
Destroy a frame buffer.
size_t frame_buffer_get_length(const frame_buffer_t *buf)
Get the current content length of the frame buffer.
const char * frame_buffer_get_content(const frame_buffer_t *buf)
Get a pointer to the buffer content.
frame_buffer_t * frame_buffer_create(int rows, int cols)
Create a new frame buffer.
void frame_buffer_printf(frame_buffer_t *buf, const char *fmt,...)
Printf-style append to the buffer.
int frame_buffer_get_screen_output_fd(void)
Get current output file descriptor for terminal screens.
struct frame_buffer frame_buffer_t
Opaque frame buffer handle.
#define SAFE_STRERROR(errnum)
unsigned long long uint64_t
bool named_metadata_copy(uintptr_t key, named_metadata_t *output)
#define GET_OPTION(field)
Definition options.h:1339
#define options_terminal_settings()
Definition options.h:1287
int utf8_display_width_n(const char *str, size_t max_bytes)
Calculate terminal display width of a UTF-8 string up to byte limit.
Definition utf8.c:106
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
const char * extract_project_relative_path(const char *file, const char *const *owned_dirs)
Extract a path relative to the source root embedded by CMake.
Definition path.c:137
int utf8_next_char_bytes(const char *str, size_t max_bytes)
Get byte length of next UTF-8 character.
Definition utf8.c:183
Capture stdout/stderr and redirect to logging system.
#define LOG_IO(prefix, block)
Definition io.h:106
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
void ascii_otel_ui_usage(const char *screen, const char *event, uint64_t duration_ns)
Definition otel.c:506
#define MIN(a, b)
Definition param.h:6
#define MAX(a, b)
Definition param.h:10
📂 Path Manipulation Utilities
asciichat_error_t ui_popup_frame(frame_buffer_t *out, int row, int col, int width, int height, log_color_t color)
Definition popup.c:55
asciichat_error_t ui_popup_rule(frame_buffer_t *out, int width, ui_popup_edge_t edge, bool double_border, bool unicode, log_color_t color)
Definition popup.c:12
@ UI_POPUP_BOTTOM
Definition popup.h:16
@ UI_POPUP_TOP
Definition popup.h:14
static bool size_t index
Definition queries.h:10
static bool size_t gotel_query_t * out
Definition queries.h:10
void ui_scrollbar_render(frame_buffer_t *out, int row, int col, int height, size_t total, size_t visible, size_t offset)
Definition scrollbar.c:46
bool terminal_should_color_output(int fd, const terminal_options_t *options)
bool terminal_should_use_utf8(terminal_utf8_setting_t user_setting)
🔤 String Manipulation and Shell Escaping Utilities
The useful part of named metadata is in its fields: together they describe what is pending,...
const char * ui_text_color_prefix(log_color_t color)
Definition text.c:18
size_t ui_text_cell(char *out, size_t cap, const char *text, int width, ui_alignment_t align)
Definition text.c:51
@ UI_ALIGN_LEFT
Definition text.h:14
void ui_too_small_render(frame_buffer_t *buffer, terminal_size_t actual, terminal_size_t minimum)
Definition too_small.c:44
bool ui_too_small(terminal_size_t actual, terminal_size_t minimum)
Definition too_small.c:10
void ui_controller_redraw(void)
🔤 UTF-8 Encoding and Decoding Utilities