ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
errno_stacks.c
Go to the documentation of this file.
1
2/* Storage capacities in elements; text buffers include the terminating NUL. */
3#define TUI_ERRNO_STACKS_FOOTER_BUFFER_SIZE 512
4#define TUI_ERRNO_STACKS_HEADER_BUFFER_SIZE 768
5#define TUI_ERRNO_STACKS_TABS_BUFFER_SIZE 256
6#define TUI_ERRNO_STACKS_COLUMNS_BUFFER_SIZE 256
7#define TUI_ERRNO_STACKS_THREAD_NAME_BUFFER_SIZE 256
8#define TUI_ERRNO_STACKS_THREAD_BUFFER_SIZE 256
9#define TUI_ERRNO_STACKS_MESSAGE_BUFFER_SIZE 256
10#define TUI_ERRNO_STACKS_USER_BUFFER_SIZE 256
11#define TUI_ERRNO_STACKS_AGE_BUFFER_SIZE 96
12#define TUI_ERRNO_STACKS_OUTCOMES_BUFFER_SIZE 128
13#define TUI_ERRNO_STACKS_CODE_BUFFER_SIZE 48
14#define TUI_ERRNO_STACKS_LINE_BUFFER_SIZE 2048
15
19#include <ascii-chat/log/log.h>
26#include <ascii-chat/ui/table.h>
27#include <ascii-chat/ui/text.h>
32#include <libplatform/compiler.h>
33#include <libplatform/lifecycle.h>
34#include <libplatform/mutex.h>
35#include <libplatform/system.h>
36#include <libplatform/terminal.h>
37#include <options/options.h>
38#include <stdlib.h>
39#include <string.h>
40
41#define ERRNO_TUI_MIN_COLS 88
42#define ERRNO_TUI_MIN_ROWS 10
43#define ERRNO_TUI_MAX_ROWS \
44 (ASCIICHAT_ERRNO_MAX_FRAMES + ASCIICHAT_ERRNO_HISTORY_SIZE)
45#define ERRNO_TUI_TABLE_BASE_WIDTH 114
46#define ERRNO_TUI_THREAD_BASE_WIDTH 14
47#define ERRNO_TUI_THREAD_MAX_WIDTH 24
48#define ERRNO_TUI_MESSAGE_BASE_WIDTH 23
49#define ERRNO_TUI_MESSAGE_MAX_WIDTH 38
50
62
85
86static errno_tui_state_t g_state;
87static mutex_t g_mutex;
88static lifecycle_t g_lifecycle = LIFECYCLE_INIT;
89
90static bool state_lock(void) {
91 if (lifecycle_init_once(&g_lifecycle)) {
92 if (mutex_init(&g_mutex, "errno_tui") != 0) {
93 lifecycle_init_abort(&g_lifecycle);
94 return false;
95 }
96 lifecycle_init_commit(&g_lifecycle);
97 }
98 if (!lifecycle_is_initialized(&g_lifecycle))
99 return false;
100 mutex_lock(&g_mutex);
101 return true;
102}
103
104static void state_unlock(void) { mutex_unlock(&g_mutex); }
105
106static int by_created_desc(const void *left, const void *right) {
107 const errno_tui_row_t *a = left, *b = right;
108 return a->context.created_ns < b->context.created_ns ? 1
109 : a->context.created_ns > b->context.created_ns ? -1
110 : 0;
111}
112
113static int by_resolved_desc(const void *left, const void *right) {
114 const errno_tui_row_t *a = left, *b = right;
115 return a->resolved_ns < b->resolved_ns ? 1
116 : a->resolved_ns > b->resolved_ns ? -1
117 : 0;
118}
119
120static int by_stack_desc(const void *left, const void *right) {
121 const errno_tui_row_t *a = left, *b = right;
122 if (a->group_id != b->group_id)
123 return a->group_timestamp < b->group_timestamp ? 1
124 : a->group_timestamp > b->group_timestamp ? -1
125 : 0;
127 uint64_t bt = b->historical ? b->resolved_ns : b->context.created_ns;
128 return at < bt ? 1 : at > bt ? -1 : 0;
129}
130
131static size_t snapshot_current(errno_tui_row_t *rows, bool stack_sort,
132 size_t capacity, size_t *stacks) {
134 size_t thread_count =
136 size_t count = 0;
137 *stacks = 0;
138 for (size_t t = 0; t < thread_count && t < ASCIICHAT_ERRNO_MAX_THREADS; ++t) {
140 size_t depth =
142 if (!depth)
143 continue;
144 ++*stacks;
145 for (size_t i = 0;
146 i < depth && i < ASCIICHAT_ERRNO_MAX_DEPTH && count < capacity; ++i) {
147 rows[count++] =
148 (errno_tui_row_t){.context = frames[i],
149 .group_id = threads[t],
150 .group_timestamp = frames[0].created_ns};
151 }
152 }
153 if (!stack_sort)
154 qsort(rows, count, sizeof(*rows), by_created_desc);
155 else {
156 /* The newest frame in each per-thread snapshot orders the group; frames
157 * remain together. */
158 qsort(rows, count, sizeof(*rows), by_stack_desc);
159 }
160 return count;
161}
162
163static size_t snapshot_history(errno_tui_row_t *rows, bool stack_sort,
164 size_t capacity) {
168 if (!history)
169 return 0;
171 size_t count = total < capacity ? total : capacity;
172 for (size_t i = 0; i < count; ++i) {
173 rows[i] = (errno_tui_row_t){.context = history[i].context,
174 .resolved_ns = history[i].resolved_ns,
175 .outcome = history[i].outcome,
176 .historical = true,
177 .group_id = history[i].context.cause_id
178 ? history[i].context.cause_id
179 : history[i].context.error_id};
180 }
181 for (size_t i = 0; i < count; ++i) {
182 uint64_t group = rows[i].group_id;
183 for (size_t depth = 0; depth < count; ++depth) {
184 bool found_parent = false;
185 for (size_t j = 0; j < count; ++j) {
186 if (rows[j].context.error_id == group && rows[j].context.cause_id) {
187 group = rows[j].context.cause_id;
188 found_parent = true;
189 break;
190 }
191 }
192 if (!found_parent)
193 break;
194 }
195 rows[i].group_id = group;
196 rows[i].group_timestamp = rows[i].resolved_ns;
197 if (stack_sort)
198 for (size_t j = 0; j < count; ++j)
199 if (rows[j].group_id == group &&
200 rows[j].resolved_ns > rows[i].group_timestamp)
201 rows[i].group_timestamp = rows[j].resolved_ns;
202 }
203 qsort(rows, count, sizeof(*rows),
204 stack_sort ? by_stack_desc : by_resolved_desc);
205 SAFE_FREE(history);
206 return count;
207}
208
209static void outcome_counts(const asciichat_errno_history_t *history,
210 size_t count, unsigned code, unsigned *resolved,
211 unsigned *dismissed, unsigned *handled) {
212 *resolved = 0;
213 *handled = 0;
214 *dismissed = 0;
215 for (size_t i = 0; i < count && i < ASCIICHAT_ERRNO_HISTORY_SIZE; ++i) {
216 if ((unsigned)history[i].context.code != code)
217 continue;
218 ++*resolved;
219 if (history[i].outcome == ASCIICHAT_ERRNO_HANDLED)
220 ++*handled;
221 else if (history[i].outcome == ASCIICHAT_ERRNO_DISMISSED)
222 ++*dismissed;
223 }
224}
225
227static void format_thread_name(uint64_t thread_id, char *output,
228 size_t output_size) {
229 named_metadata_t metadata = {0};
230 if (named_metadata_copy((uintptr_t)thread_id, &metadata) &&
231 metadata.name[0]) {
232 safe_snprintf(output, output_size, "%s", metadata.name);
233 return;
234 }
235 safe_snprintf(output, output_size, "0x%llx", (unsigned long long)thread_id);
236}
237
238static void put_color(frame_buffer_t *buffer, log_color_t color, bool enabled) {
239 frame_buffer_printf(buffer, "%s",
240 (enabled ? ui_text_color_prefix(color) : ""));
241}
242
243static size_t duration_number_length(const char *duration) {
244 size_t length = 0;
245 while (duration[length] &&
246 ((duration[length] >= '0' && duration[length] <= '9') ||
247 duration[length] == '.'))
248 ++length;
249 return length;
250}
251
252static void render_footer(frame_buffer_t *buffer, int width, bool colors) {
253 const char *orange = (colors ? ui_text_color_prefix(LOG_COLOR_DEV) : "");
254 const char *grey = (colors ? ui_text_color_prefix(LOG_COLOR_GREY) : "");
255 const char *reset = (colors ? ui_text_color_prefix(LOG_COLOR_RESET) : "");
257 safe_snprintf(footer, sizeof(footer),
258 "%sTab%s%s: tab %ss%s%s: sort %sUp%s/%sk%s/%sDown%s/%sj%s%s: "
259 "move %sx%s%s: clear %s'%s/%sEsc%s%s: close",
260 orange, reset, grey, orange, reset, grey, orange, reset, orange,
261 reset, orange, reset, orange, reset, grey, orange, reset, grey,
262 orange, reset, orange, reset, grey);
263 frame_buffer_render_centered(buffer, footer, width);
264}
265
266static void render_table_line(frame_buffer_t *buffer, const char *line,
267 int width) {
268 int table_width = width - 4;
269 int left_padding = (width - table_width) / 2;
270 frame_buffer_printf(buffer, "%*s%s\n", left_padding, "", line);
271}
272
273static int table_width_for_terminal(int width) { return width - 4; }
274
275static int growing_column_width(int table_width, int base_width, int max_width,
276 int divisor) {
277 int extra_width = MAX(table_width - ERRNO_TUI_TABLE_BASE_WIDTH, 0);
278 return MIN(base_width + extra_width / divisor, max_width);
279}
280
282static void render_errno_stacks(terminal_size_t size, const void *unused) {
283 (void)unused;
284 errno_tui_state_t state;
285 if (!state_lock())
286 return;
287 state = g_state;
288 state_unlock();
289
290 frame_buffer_t *buffer = frame_buffer_create(size.rows, size.cols);
291 if (!buffer)
292 return;
293 frame_buffer_append(buffer, "\033[0m", 4);
295 const terminal_size_t minimum = {.cols = ERRNO_TUI_MIN_COLS,
296 .rows = ERRNO_TUI_MIN_ROWS};
297 int output_fd = state.output_fd >= 0 ? state.output_fd : STDOUT_FILENO;
298 if (ui_too_small(size, minimum)) {
299 ui_too_small_render(buffer, size, minimum);
302 frame_buffer_destroy(buffer);
303 return;
304 }
305
306 bool colors =
307 !GET_OPTION(strip_ansi) &&
309 errno_tui_row_t *rows =
311 errno_tui_row_t *current_rows =
312 SAFE_CALLOC(ERRNO_TUI_MAX_ROWS, sizeof(*current_rows), errno_tui_row_t *);
313 if (!rows || !current_rows) {
314 SAFE_FREE(rows);
315 SAFE_FREE(current_rows);
316 frame_buffer_destroy(buffer);
317 return;
318 }
319 size_t stacks = 0;
320 size_t current_count = snapshot_current(current_rows, state.stack_sort,
321 ERRNO_TUI_MAX_ROWS, &stacks);
322 size_t count = 0;
323 if (state.tab == ERRNO_TUI_CURRENT) {
324 memcpy(rows, current_rows, current_count * sizeof(*rows));
325 count = current_count;
326 } else {
327 count = snapshot_history(rows, state.stack_sort, ERRNO_TUI_MAX_ROWS);
328 }
329 ui_layout_t layout;
330 if (ui_layout_measure(size, 4, 1, 2, &layout) != ASCIICHAT_OK) {
331 SAFE_FREE(current_rows);
332 SAFE_FREE(rows);
333 frame_buffer_destroy(buffer);
334 return;
335 }
336 int list_rows = layout.body_rows;
337 if (list_rows < 1)
338 list_rows = 1;
339 if (state_lock()) {
340 g_state.rows = list_rows;
341 g_state.count = (int)count;
342 ui_selectable_list_keep_visible(&g_state.list, (int)count, list_rows);
343 g_state.selected_current = state.tab == ERRNO_TUI_CURRENT &&
344 g_state.list.selected >= 0 &&
345 g_state.list.selected < (int)count;
346 if (g_state.selected_current)
347 g_state.selected_context = rows[g_state.list.selected].context;
348 state = g_state;
349 state_unlock();
350 }
351
352 int width = size.cols - 1;
353 bool utf8 = utf8_output_enabled();
358 size_t old_count =
360 : 0;
361 uint64_t latest = 0;
362 for (size_t i = 0; i < current_count; ++i)
363 if (current_rows[i].context.created_ns > latest)
364 latest = current_rows[i].context.created_ns;
365 for (size_t i = 0; i < old_count; ++i)
366 if (history[i].resolved_ns > latest)
367 latest = history[i].resolved_ns;
369 const char *blue = (colors ? ui_text_color_prefix(LOG_COLOR_DEBUG) : "");
370 const char *purple = (colors ? ui_text_color_prefix(LOG_COLOR_FATAL) : "");
371 const char *reset = (colors ? ui_text_color_prefix(LOG_COLOR_RESET) : "");
372 int header_length = safe_snprintf(
373 header, sizeof(header),
374 "%serrno stacks%s errors %s%zu%s stacks %s%zu%s old %s%zu%s", blue,
375 reset, purple, current_count, reset, purple, stacks, reset, purple,
376 old_count, reset);
377 if (latest && header_length > 0 && (size_t)header_length < sizeof(header)) {
379 time_pretty(time_get_ns() - latest, -1, ago, sizeof(ago));
380 size_t value_length = duration_number_length(ago);
381 safe_snprintf(header + header_length,
382 sizeof(header) - (size_t)header_length,
383 " latest %s%.*s%s%s ago", purple, (int)value_length, ago,
384 reset, ago + value_length);
385 }
386 frame_buffer_render_centered(buffer, header, width);
389 safe_snprintf(tabs, sizeof(tabs), "Current | Past %s sort",
390 state.stack_sort ? "stack" : "recent");
391 frame_buffer_render_centered(buffer, tabs, width);
392 int table_width = table_width_for_terminal(width);
393 int thread_width = growing_column_width(
395 int message_width =
396 growing_column_width(table_width, ERRNO_TUI_MESSAGE_BASE_WIDTH,
398 int user_width = table_width - 28 - thread_width - message_width;
400 safe_snprintf(columns, sizeof(columns),
401 "%sAgo R/D/H Code %-*s %-*s User message%s", blue,
402 thread_width, "Thread", message_width, "Standard message",
403 reset);
404 render_table_line(buffer, columns, width);
405
406 for (int i = 0; i < list_rows; ++i) {
407 int index = state.list.first_visible + i;
408 if (index >= (int)count) {
409 frame_buffer_printf(buffer, "\n");
410 continue;
411 }
412 const errno_tui_row_t *row = &rows[index];
418 uint64_t timestamp =
419 row->historical ? row->resolved_ns : row->context.created_ns;
420 time_pretty(time_get_ns() - timestamp, -1, ago, sizeof(ago));
421 size_t ago_value_length = duration_number_length(ago);
422 format_thread_name(row->context.thread_id, thread_name,
423 sizeof(thread_name));
424 truncate_with_ellipsis(thread_name, thread, sizeof(thread), thread_width);
425 truncate_with_ellipsis(asciichat_error_string(row->context.code), message,
426 sizeof(message), message_width);
427 truncate_with_ellipsis(row->context.context_message, user, sizeof(user),
428 user_width);
429 unsigned resolved, dismissed, handled;
430 outcome_counts(history, old_count, (unsigned)row->context.code, &resolved,
431 &dismissed, &handled);
436 safe_snprintf(age, sizeof(age), "%s%.*s%s%s", purple, (int)ago_value_length,
437 ago, reset, ago + ago_value_length);
438 safe_snprintf(outcomes, sizeof(outcomes), "%s%u%s/%s%u%s/%s%u%s", purple,
439 resolved, reset, purple, dismissed, reset, purple, handled,
440 reset);
441 safe_snprintf(code, sizeof(code), "%s%d%s", purple, row->context.code,
442 reset);
443 const ui_table_column_t table_columns[] = {
444 {"Ago", 10, UI_ALIGN_LEFT, false},
445 {"R/D/H", 8, UI_ALIGN_LEFT, false},
446 {"Code", 5, UI_ALIGN_LEFT, false},
447 {"Thread", thread_width, UI_ALIGN_LEFT, true},
448 {"Standard message", message_width, UI_ALIGN_LEFT, true},
449 {"User message", user_width, UI_ALIGN_LEFT, true}};
450 const char *cells[] = {age, outcomes, code, thread, message, user};
451 ui_table_row(line, sizeof(line), table_columns, cells, 6, table_width, true,
452 index == state.list.selected);
453 render_table_line(buffer, line, width);
454 }
455 ui_scrollbar_render(buffer, 5, width - 1, list_rows, count, (size_t)list_rows,
456 (size_t)state.list.first_visible);
458 render_footer(buffer, width, colors);
459 put_color(buffer, LOG_COLOR_RESET, colors);
462 SAFE_FREE(history);
463 SAFE_FREE(current_rows);
464 SAFE_FREE(rows);
465 frame_buffer_destroy(buffer);
466}
467
468static void publish(void) {
469 const unsigned marker = 1;
470 int fd = STDOUT_FILENO;
471 if (state_lock()) {
472 fd = g_state.output_fd >= 0 ? g_state.output_fd : STDOUT_FILENO;
473 state_unlock();
474 }
476 (terminal_size_t){.cols = ERRNO_TUI_MIN_COLS,
477 .rows = ERRNO_TUI_MIN_ROWS},
478 render_errno_stacks, &marker,
479 sizeof(marker)) != ASCIICHAT_OK)
480 CLEAR_ERRNO();
481}
482
484#if defined(ASCIICHAT_DIAGNOSTIC_UI)
485 if (!state_lock())
486 return;
487 g_state.visible = !g_state.visible;
488 if (g_state.visible)
489 ui_selectable_list_reset(&g_state.list);
490 if (g_state.visible)
491 g_state.output_fd = ui_controller_active_fd();
492 bool visible = g_state.visible;
493 state_unlock();
494 if (visible)
495 publish();
496 else
498#endif
499}
500
502 if (!state_lock())
503 return;
504 g_state.visible = false;
505 state_unlock();
507}
508
510 if (!state_lock())
511 return false;
512 bool visible = g_state.visible;
513 state_unlock();
514 return visible;
515}
516
517bool ui_errno_stacks_handle_key(keyboard_key_t key) {
520 return false;
521 if (!state_lock())
522 return false;
523 if (key == KEY_BACKTICK || key == KEY_ESCAPE) {
524 g_state.visible = false;
525 state_unlock();
527 return true;
528 }
529 if (key == '\t') {
530 g_state.tab = g_state.tab == ERRNO_TUI_CURRENT ? ERRNO_TUI_HISTORY
532 ui_selectable_list_reset(&g_state.list);
533 } else if (key == 's' || key == 'S') {
534 g_state.stack_sort = !g_state.stack_sort;
535 ui_selectable_list_reset(&g_state.list);
536 } else if (key == KEY_UP || key == 'k') {
537 ui_selectable_list_move(&g_state.list, g_state.count, g_state.rows, -1);
538 } else if (key == KEY_DOWN || key == 'j') {
539 ui_selectable_list_move(&g_state.list, g_state.count, g_state.rows, 1);
540 } else if (key == 'x' || key == 'X') {
541 errno_tui_state_t state = g_state;
542 state_unlock();
543 if (state.selected_current)
547 publish();
548 return true;
549 } else {
550 state_unlock();
551 return false;
552 }
553 state_unlock();
554 publish();
555 return true;
556}
bool errno_clear_if_current(uint64_t id, uint64_t generation, uint64_t error_id)
size_t errno_threads_snapshot(uint64_t *out, size_t capacity)
asciichat_errno_snapshot_t errno_snapshot(uint64_t id, asciichat_error_context_t *out, size_t capacity)
size_t errno_history_snapshot(asciichat_errno_history_t *out, size_t capacity)
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define ASCIICHAT_ERRNO_MAX_THREADS
#define ASCIICHAT_ERRNO_HISTORY_SIZE
#define CLEAR_ERRNO()
asciichat_errno_outcome_t
@ ASCIICHAT_ERRNO_HANDLED
@ ASCIICHAT_ERRNO_DISMISSED
#define ASCIICHAT_ERRNO_MAX_DEPTH
log_color_t
Definition color.h:6
@ LOG_COLOR_RESET
Definition color.h:14
@ LOG_COLOR_GREY
Definition color.h:13
@ LOG_COLOR_FATAL
Definition color.h:12
@ LOG_COLOR_DEV
Definition color.h:7
@ LOG_COLOR_DEBUG
Definition color.h:8
Named object registry for debugging — log identifiable resource names.
#define ERRNO_TUI_MESSAGE_BASE_WIDTH
#define TUI_ERRNO_STACKS_MESSAGE_BUFFER_SIZE
Definition errno_stacks.c:9
#define ERRNO_TUI_MIN_COLS
#define TUI_ERRNO_STACKS_HEADER_BUFFER_SIZE
Definition errno_stacks.c:4
#define TUI_ERRNO_STACKS_USER_BUFFER_SIZE
#define ERRNO_TUI_THREAD_MAX_WIDTH
#define TUI_ERRNO_STACKS_AGE_BUFFER_SIZE
#define TUI_ERRNO_STACKS_FOOTER_BUFFER_SIZE
Definition errno_stacks.c:3
#define ERRNO_TUI_MIN_ROWS
#define ERRNO_TUI_TABLE_BASE_WIDTH
void ui_errno_stacks_toggle(void)
#define ERRNO_TUI_THREAD_BASE_WIDTH
#define TUI_ERRNO_STACKS_CODE_BUFFER_SIZE
#define TUI_ERRNO_STACKS_THREAD_NAME_BUFFER_SIZE
Definition errno_stacks.c:7
bool ui_errno_stacks_visible(void)
#define TUI_ERRNO_STACKS_COLUMNS_BUFFER_SIZE
Definition errno_stacks.c:6
errno_tui_tab_t
@ ERRNO_TUI_CURRENT
@ ERRNO_TUI_HISTORY
#define ERRNO_TUI_MESSAGE_MAX_WIDTH
#define TUI_ERRNO_STACKS_THREAD_BUFFER_SIZE
Definition errno_stacks.c:8
void ui_errno_stacks_hide(void)
bool ui_errno_stacks_handle_key(keyboard_key_t key)
#define TUI_ERRNO_STACKS_TABS_BUFFER_SIZE
Definition errno_stacks.c:5
#define ERRNO_TUI_MAX_ROWS
#define TUI_ERRNO_STACKS_LINE_BUFFER_SIZE
#define TUI_ERRNO_STACKS_OUTCOMES_BUFFER_SIZE
Error and exit codes - unified status values (0-255).
char cells[(512 *256 *2)]
Definition fft.c:22
unsigned char colors[(512 *256 *2) *3]
Definition fft.c:23
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.
int frame_buffer_render_centered(frame_buffer_t *buf, const char *text, int cols)
Render centered text (used by both splash and status screens).
void frame_buffer_destroy(frame_buffer_t *buf)
Destroy a frame buffer.
void frame_buffer_render_divider(frame_buffer_t *buf, int width, bool use_utf8, bool use_colors)
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.
void frame_buffer_clear_screen(frame_buffer_t *buf)
Append clear screen and home escape codes (\033[2J\033[H).
Buffered terminal frame rendering.
struct frame_buffer frame_buffer_t
Opaque frame buffer handle.
bool enabled
Is filtering active?
Definition grep.c:63
#define SAFE_FREE(ptr)
#define SAFE_CALLOC(count, size, cast)
unsigned long long uint64_t
bool named_metadata_copy(uintptr_t key, named_metadata_t *output)
@ ASCIICHAT_OK
Definition error_codes.h:50
int time_pretty(uint64_t nanoseconds, int decimals, char *buffer, size_t buffer_size)
Format nanoseconds as a compact duration with configurable sub-minute precision.
Definition time.c:406
#define TIME_DURATION_BUFFER_SIZE
Definition time.h:40
#define GET_OPTION(field)
Definition options.h:1339
#define options_terminal_settings()
Definition options.h:1287
bool utf8_output_enabled(void)
Return whether terminal output should use UTF-8 according to –utf8.
Definition utf8.c:22
void truncate_with_ellipsis(const char *input, char *output, size_t output_size, int max_width)
Truncate a string to a maximum display width, with ellipsis.
🖥️ Display Width and Terminal Centering Utilities
📝 Logging API with multiple log levels and terminal output control
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
#define MIN(a, b)
Definition param.h:6
#define MAX(a, b)
Definition param.h:10
static bool size_t index
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
void ui_selectable_list_move(ui_selectable_list_t *list, int count, int rows, int delta)
void ui_selectable_list_reset(ui_selectable_list_t *list)
void ui_selectable_list_keep_visible(ui_selectable_list_t *list, int count, int rows)
bool terminal_should_color_output(int fd, const terminal_options_t *options)
🔤 String Manipulation and Shell Escaping Utilities
uint64_t created_ns
Monotonic time, for age.
uint64_t group_timestamp
asciichat_error_context_t context
uint64_t resolved_ns
asciichat_errno_outcome_t outcome
uint64_t group_id
The useful part of errno tui row is in context, resolved_ns, group_id, group_timestamp: together they...
ui_selectable_list_t list
errno_tui_tab_t tab
asciichat_error_context_t selected_context
The useful part of named metadata is in its fields: together they describe what is pending,...
int body_rows
Definition ui/layout.h:9
ui selectable list keeps the values that move through the subsystem: selected, first_visible....
size_t ui_table_row(char *out, size_t cap, const ui_table_column_t *cols, const char *const *cells, size_t count, int width, bool selectable, bool selected)
When code needs to work with ui table, it keeps columns, column_count, row_count, viewport here inste...
Definition table.c:18
const char * ui_text_color_prefix(log_color_t color)
Definition text.c:18
@ UI_ALIGN_LEFT
Definition text.h:14
⏱️ High-precision timing utilities using sokol_time.h and uthash
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_remove(ui_screen_t screen)
asciichat_error_t ui_controller_submit(ui_screen_t screen, int fd, terminal_size_t minimum, ui_render_fn render, const void *snapshot, size_t bytes)
int ui_controller_current_screen(void)
asciichat_error_t ui_controller_write(int fd, const char *data, size_t len)
int ui_controller_active_fd(void)
@ UI_SCREEN_ERRNO
asciichat_error_t ui_layout_measure(terminal_size_t size, int header, int detail, int footer, ui_layout_t *out)
Definition ui/layout.c:3
🔤 UTF-8 Encoding and Decoding Utilities