ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
session_status.c
Go to the documentation of this file.
1
2/* Storage capacities in elements; text buffers include the terminating NUL. */
3#define TUI_SESSION_STATUS_STATUS_LINE_BUFFER_SIZE 512
4#define TUI_SESSION_STATUS_STATUS_LINE_TRUNCATED_BUFFER_SIZE 512
5#define TUI_SESSION_STATUS_STATUS_LINE_COLORED_BUFFER_SIZE 600
6#define TUI_SESSION_STATUS_UPTIME_BUFFER_SIZE 12
7#define TUI_SESSION_STATUS_ADDR_LINE_BUFFER_SIZE 512
8#define TUI_SESSION_STATUS_ADDR_LINE_TRUNCATED_BUFFER_SIZE 512
9#define TUI_SESSION_STATUS_IPV4_ONLY_BUFFER_SIZE 64
10#define TUI_SESSION_STATUS_IPV6_ONLY_BUFFER_SIZE 64
11#define TUI_SESSION_STATUS_TEXT_BUFFER_SIZE 2048
12#define TUI_SESSION_STATUS_FOOTER_BUFFER_SIZE 128
13#define TUI_SESSION_STATUS_KEYS_BUFFER_SIZE 96
14
18#include <ascii-chat/log/grep.h>
23#include <ascii-chat/ui/popup.h>
25#include <ascii-chat/util/ip.h>
29#include <libplatform/mutex.h>
30#include <options/options.h>
31#include <stdio.h>
32#include <string.h>
33
34void ui_status_render_header(frame_buffer_t *buf, terminal_size_t term_size,
35 void *user_data) {
36 const ui_status_t *status = (const ui_status_t *)user_data;
37 if (!status) {
38 return;
39 }
40
41 // Calculate uptime
42 time_t now = time(NULL);
43 time_t uptime_secs = now - status->start_time;
44 int uptime_hours = (int)(uptime_secs / SEC_PER_HOUR);
45 int uptime_mins = (int)((uptime_secs % SEC_PER_HOUR) / SEC_PER_MIN);
46 int uptime_secs_rem = (int)(uptime_secs % 60);
47
48 // Line 1: Top border
49 bool unicode = terminal_should_use_utf8(GET_OPTION(force_utf8));
50 bool colors =
51 !GET_OPTION(strip_ansi) &&
54 frame_buffer_render_divider(buf, term_size.cols - 1, unicode, colors);
55
56 // The bundled browser font does not contain the emoji used in native status
57 // titles.
58#ifdef __EMSCRIPTEN__
59 bool status_icons = false;
60#else
61 bool status_icons = unicode;
62#endif
63
64 // Line 2: Title + Stats (centered)
66 char status_line_truncated
70 format_uptime_hms(uptime_hours, uptime_mins, uptime_secs_rem, uptime_str,
71 sizeof(uptime_str));
72 bool generic_log_header =
73 status->detail && strstr(status->detail, "keyboard controls") != NULL;
74 if (generic_log_header)
75 snprintf(status_line, sizeof(status_line),
76 status_icons ? "ascii-chat | ⏱️ %s" : "ascii-chat | uptime %s",
77 uptime_str);
78 else if (status->detail)
79 snprintf(status_line, sizeof(status_line),
80 status_icons ? "ascii-chat %s | ⏱️ %s"
81 : "ascii-chat %s | uptime %s",
82 status->mode_name, uptime_str);
83 else
84 snprintf(status_line, sizeof(status_line),
85 status_icons ? "ascii-chat %s | 👥 %zu | ⏱️ %s"
86 : "ascii-chat %s | clients %zu | uptime %s",
87 status->mode_name, status->connected_count, uptime_str);
88
89 // Truncate if needed (ANSI-aware)
90 truncate_with_ellipsis(status_line, status_line_truncated,
91 sizeof(status_line_truncated), term_size.cols - 2);
92 snprintf(status_line_colored, sizeof(status_line_colored), "\033[1m%s\033[0m",
93 colored_string(LOG_COLOR_DEBUG, status_line_truncated));
94
95 int padding =
96 display_center_horizontal(status_line_truncated, term_size.cols);
97 for (int i = 0; i < padding; i++) {
98 frame_buffer_printf(buf, " ");
99 }
100 frame_buffer_printf(buf, "%s\n", status_line_colored);
101
102 // Line 3: Session + Addresses (centered)
103 char addr_line[TUI_SESSION_STATUS_ADDR_LINE_BUFFER_SIZE] = {0};
105 int pos = 0;
106 if (status->session_string[0] != '\0') {
107 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos,
108 unicode ? "🔗 %s" : "Session %s", status->session_string);
109 }
110 if (status->ipv4_bound && pos < (int)sizeof(addr_line) - 30) {
111 if (pos > 0) {
112 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, " | ");
113 }
114 // Extract IP and get type
116 if (extract_ip_from_address(status->ipv4_address, ipv4_only,
117 sizeof(ipv4_only)) == 0) {
118 const char *type = get_ip_type_string(ipv4_only);
119 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s (%s)",
120 status->ipv4_address, type);
121 } else {
122 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s",
123 status->ipv4_address);
124 }
125 }
126 if (status->ipv6_bound && pos < (int)sizeof(addr_line) - 30) {
127 if (pos > 0) {
128 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, " | ");
129 }
130 // Extract IP and get type
132 if (extract_ip_from_address(status->ipv6_address, ipv6_only,
133 sizeof(ipv6_only)) == 0) {
134 const char *type = get_ip_type_string(ipv6_only);
135 snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s (%s)",
136 status->ipv6_address, type);
137 } else {
138 snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s",
139 status->ipv6_address);
140 }
141 }
142
143 if (status->detail)
144 SAFE_STRNCPY(addr_line, status->detail, sizeof(addr_line));
145
146 // Truncate if needed (ANSI-aware)
147 truncate_with_ellipsis(addr_line, addr_line_truncated,
148 sizeof(addr_line_truncated), term_size.cols - 2);
149
150 int addr_padding =
151 display_center_horizontal(addr_line_truncated, term_size.cols);
152 for (int i = 0; i < addr_padding; i++) {
153 frame_buffer_printf(buf, " ");
154 }
155 frame_buffer_printf(buf, "%s\n", addr_line_truncated);
156
157 // Line 4: Bottom border
158 frame_buffer_render_divider(buf, term_size.cols - 1, unicode, colors);
159}
160
161typedef struct {
162 size_t entry;
163 int row;
171
172static const char *startup_log_summary(const char *message, char *buffer,
173 size_t buffer_size) {
174 if (!message || !buffer || !buffer_size)
175 return message;
176
177 char plain[SESSION_LOG_LINE_MAX];
178 strip_ansi_codes(message, plain, sizeof(plain));
179 const char *summary = strstr(plain, "(): ");
180 if (summary)
181 summary += 4;
182 else {
183 summary = strrchr(plain, ']');
184 summary = summary ? summary + 1 : plain;
185 while (*summary == ' ')
186 ++summary;
187 }
188
189 snprintf(buffer, buffer_size, "[ * ] %s", summary);
190 return buffer;
191}
192
193static int log_message_rows(const char *message, int width,
194 bool compact_startup) {
195 char formatted[SESSION_LOG_LINE_MAX + 32];
196 if (compact_startup)
197 message = startup_log_summary(message, formatted, sizeof(formatted));
198 int rows = display_height(message, width);
199 return rows > 0 ? rows : 1;
200}
201
202static size_t utf8_byte_offset_for_char(const char *text,
203 size_t character_offset) {
204 const char *cursor = text;
205 while (*cursor && character_offset) {
206 uint32_t codepoint;
207 int length = utf8_decode((const uint8_t *)cursor, &codepoint);
208 cursor += length > 0 ? length : 1;
209 --character_offset;
210 }
211 return (size_t)(cursor - text);
212}
213
214static void append_log_row(frame_buffer_t *body, const char *message, int row,
215 int width, bool compact_startup) {
216 char formatted[SESSION_LOG_LINE_MAX + 32];
217 if (compact_startup) {
218 message = startup_log_summary(message, formatted, sizeof(formatted));
219 }
220 char plain[SESSION_LOG_LINE_MAX];
221 strip_ansi_codes(message, plain, sizeof(plain));
222 const char *start = plain;
223 size_t remaining = strlen(plain);
224 for (int i = 0; i < row && remaining; ++i) {
225 size_t prefix = utf8_prefix_bytes_for_width(start, remaining, width);
226 if (!prefix)
227 break;
228 start += prefix;
229 remaining -= prefix;
230 }
231 if (!remaining) {
232 frame_buffer_printf(body, "\n");
233 return;
234 }
235 size_t length = utf8_prefix_bytes_for_width(start, remaining, width);
236 if (!length) {
237 frame_buffer_printf(body, "\n");
238 return;
239 }
240 if (compact_startup) {
241 char line[SESSION_LOG_LINE_MAX];
242 memcpy(line, start, length);
243 line[length] = '\0';
244 bool startup_marker =
245 compact_startup && row == 0 && strncmp(line, "[ * ] ", 6) == 0;
246 const char *content = startup_marker ? line + 6 : line;
247 size_t match_start = 0;
248 size_t match_length = 0;
249 const char *rendered = content;
250 if (log_search_get_match_info(content, &match_start, &match_length)) {
251 size_t start_byte = utf8_byte_offset_for_char(content, match_start);
252 size_t end_byte =
253 utf8_byte_offset_for_char(content, match_start + match_length);
254 rendered = grep_highlight(content, start_byte, end_byte - start_byte);
255 }
256 if (startup_marker)
257 frame_buffer_printf(body, "%s%s%s ",
261 frame_buffer_printf(body, "%s\033[0m\n", rendered);
262 return;
263 }
264 size_t match_start = 0, match_length = 0;
265 const char *rendered = message;
266 if (log_search_get_match_info(plain, &match_start, &match_length)) {
267 size_t start_byte = utf8_byte_offset_for_char(plain, match_start);
268 size_t end_byte =
269 utf8_byte_offset_for_char(plain, match_start + match_length);
270 rendered = grep_highlight_colored(message, plain, start_byte,
271 end_byte - start_byte);
272 }
273 // Replay preceding SGR sequences so wrapped rows retain their original style.
274 size_t first = (size_t)(start - plain), last = first + length, offset = 0;
275 for (const char *cursor = rendered; *cursor && offset < last;) {
276 if (cursor[0] == '\033' && cursor[1] == '[') {
277 const char *escape = cursor;
278 cursor += 2;
279 while (*cursor && !(*cursor >= '@' && *cursor <= '~'))
280 ++cursor;
281 if (*cursor) {
282 if (*cursor++ == 'm')
283 frame_buffer_append(body, escape, (size_t)(cursor - escape));
284 }
285 } else {
286 if (offset >= first)
287 frame_buffer_append(body, cursor, 1);
288 ++cursor;
289 ++offset;
290 }
291 }
292 frame_buffer_printf(body, "\033[0m\n");
293}
294
295void terminal_screen_compose(frame_buffer_t *output, terminal_size_t size,
296 const terminal_screen_config_t *config,
297 session_log_buffer_t *logs) {
298 if (!output || !config || !config->render_header || size.cols < 1 ||
299 size.rows < 1)
300 return;
301 if (config->show_logs)
303 frame_buffer_t *body = frame_buffer_create(size.rows, size.cols);
304 if (!body)
305 return;
306 config->render_header(body, size, config->user_data);
307
308 // Measure the actual header, including wrapped lines, as the native status UI
309 // does.
310 int header_rows = 0;
311 const char *line = frame_buffer_get_content(body);
312 const char *end = line + frame_buffer_get_length(body);
313 for (const char *cursor = line; cursor < end; ++cursor) {
314 if (*cursor == '\n') {
316 size_t length = (size_t)(cursor - line);
317 if (length >= sizeof(text))
318 length = sizeof(text) - 1;
319 memcpy(text, line, length);
320 text[length] = '\0';
321 int height = display_height(text, size.cols);
322 header_rows += height > 0 ? height : 1;
323 line = cursor + 1;
324 }
325 }
326 if (!header_rows)
327 header_rows = config->fixed_header_lines;
328 bool entering = config->show_logs && log_search_is_entering();
329 // Search owns the final row for its prompt. Otherwise logs fill it.
330 int available = size.rows - header_rows - (entering ? 1 : 0);
331 bool compact_startup = config->screen == UI_SCREEN_SPLASH;
332 session_log_entry_t *entries = NULL;
333 size_t count = 0;
334 size_t scroll_total = 0, scroll_offset = 0;
335 if (config->show_logs && available > 0) {
337 log_search_filter_buffer(logs, &entries, &count);
338 else {
339 entries = SAFE_MALLOC(SESSION_LOG_BUFFER_SIZE * sizeof(*entries),
341 if (entries)
342 count = session_log_buffer_get_recent(logs, entries,
344 }
345 log_row_ref_t *rows =
346 SAFE_MALLOC((size_t)available * sizeof(*rows), log_row_ref_t *);
347 if (rows) {
348 size_t total_rows = 0;
349 uint64_t previous_tail_sequence = 0;
350 size_t appended_rows = 0;
351 for (size_t entry = 0; entry < count; ++entry) {
352 size_t height = (size_t)log_message_rows(entries[entry].message,
353 size.cols, compact_startup);
354 if (SIZE_MAX - total_rows < height)
355 total_rows = SIZE_MAX;
356 else
357 total_rows += height;
358 }
359 uint64_t tail_sequence = count ? entries[count - 1].sequence : 0;
360 previous_tail_sequence = terminal_screen_logs_last_tail_sequence();
361 if (previous_tail_sequence && tail_sequence > previous_tail_sequence) {
362 for (size_t entry = 0; entry < count; ++entry) {
363 if (entries[entry].sequence > previous_tail_sequence)
364 appended_rows += (size_t)log_message_rows(
365 entries[entry].message, size.cols, compact_startup);
366 }
367 }
368 size_t max_offset = total_rows ? total_rows - 1 : 0;
370 tail_sequence, appended_rows, max_offset);
371 scroll_total = total_rows;
372 scroll_offset = total_rows > (size_t)available + skip
373 ? total_rows - (size_t)available - skip
374 : 0;
375 size_t row_count = 0;
376 for (size_t entry = count; entry && row_count < (size_t)available;
377 --entry) {
378 int height = log_message_rows(entries[entry - 1].message, size.cols,
379 compact_startup);
380 if (skip >= (size_t)height) {
381 skip -= (size_t)height;
382 continue;
383 }
384 int row = height - 1 - (int)skip;
385 skip = 0;
386 for (; row >= 0 && row_count < (size_t)available; --row)
387 rows[row_count++] = (log_row_ref_t){.entry = entry - 1, .row = row};
388 }
389 for (size_t row = row_count; row; --row)
390 append_log_row(body, entries[rows[row - 1].entry].message,
391 rows[row - 1].row, size.cols, compact_startup);
392 while (row_count++ < (size_t)available)
393 frame_buffer_printf(body, "\n");
394 SAFE_FREE(rows);
395 }
396 }
397 SAFE_FREE(entries);
398
399 // Preserve the existing repaint-in-place behavior, also supplying CR for
400 // browser terminals.
401 bool log_help_open = config->show_logs && terminal_screen_logs_help_open();
402 bool hide_cursor = log_help_open ||
403 (!entering && (config->hide_cursor || config->show_logs));
404 frame_buffer_printf(output, "\033[H%s",
405 hide_cursor ? "\033[?25l" : "\033[?25h");
406 const char *content = frame_buffer_get_content(body);
407 size_t length = frame_buffer_get_length(body);
408 for (size_t i = 0; i < length; ++i) {
409 // Normalize CRLF before erasing the line; erasing after CR removes its
410 // text.
411 if (content[i] == '\r' && i + 1 < length && content[i + 1] == '\n')
412 continue;
413 if (content[i] == '\n') {
414 frame_buffer_printf(output, "\033[K\r");
415 // Do not advance past the bottom row when the idle log view fills it.
416 if (config->show_logs && !entering && i + 1 == length)
417 continue;
418 }
419 frame_buffer_append(output, content + i, 1);
420 }
421 if (config->show_logs && available > 0 && scroll_total > (size_t)available)
422 ui_scrollbar_render(output, header_rows + 1, size.cols, available,
423 scroll_total, (size_t)available, scroll_offset);
424 if (entering) {
425 mutex_t *mutex = log_search_get_mutex();
426 mutex_lock(mutex);
427 const char *pattern = log_search_get_input_buffer();
428 int cursor = log_search_get_cursor_position();
429 // Keep the edit cursor visible even when a pattern exceeds the viewport.
430 int offset = cursor >= size.cols - 2 ? cursor - (size.cols - 3) : 0;
431 frame_buffer_printf(output, "\033[%d;1H/%.*s\033[K\033[%d;%dH", size.rows,
432 size.cols - 2, pattern ? pattern + offset : "",
433 size.rows, cursor - offset + 2);
434 mutex_unlock(mutex);
435 }
436 if (log_help_open) {
438 } else if (config->show_logs && terminal_screen_logs_help_too_small()) {
439 frame_buffer_printf(output, "\033[%d;1H%s", size.rows,
440 "Help needs at least 12 terminal rows");
441 }
443}
444
446 terminal_size_t size) {
447 const ui_help_entry_t entries[] = {
448 {"Down", "newer log"}, {"Up", "older log"},
449 {"PageDown", "newer page"}, {"PageUp", "older page"},
450 {"End", "newest log"}, {"Home", "oldest log"},
451 {"/", "search logs"}, {"q / Esc", "close viewer"}};
454 ui_help_keys(keys, sizeof(keys), "? / Esc");
455 snprintf(footer, sizeof(footer), "%s closes this help", keys);
456 ui_help_menu_t menu = {.title = "Log Viewer Keyboard Controls",
457 .entries = entries,
458 .count = sizeof(entries) / sizeof(*entries),
459 .footer = footer};
460 (void)ui_help_menu_render(output, size, &menu);
461}
@ LOG_COLOR_DEBUG
Definition color.h:8
@ LOG_COLOR_WARN
Definition color.h:10
@ LOG_COLOR_WHITE
Definition color.h:15
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.
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.
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.
const char * grep_highlight(const char *log_line, size_t match_start, size_t match_len)
Highlight matched portion with background color.
Definition grep.c:1057
int buffer_size
Size of circular buffer.
Definition grep.c:69
const char * grep_highlight_colored(const char *colored_text, const char *plain_text, size_t match_start, size_t match_len)
Highlight matches in colored text while preserving original colors.
Definition grep.c:702
unsigned int uint32_t
#define SAFE_STRNCPY(dst, src, size)
#define SAFE_FREE(ptr)
#define SAFE_MALLOC(size, cast)
unsigned long long uint64_t
unsigned char uint8_t
struct session_log_buffer session_log_buffer_t
Thread-safe fixed-size history ring for session-screen log lines.
#define SEC_PER_HOUR
Definition time.h:184
int format_uptime_hms(int hours, int minutes, int seconds, char *buffer, size_t buffer_size)
Format uptime as HH:MM:SS string.
Definition time.c:346
#define SEC_PER_MIN
Definition time.h:183
#define GET_OPTION(field)
Definition options.h:1339
#define options_terminal_settings()
Definition options.h:1287
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
int utf8_decode(const uint8_t *s, uint32_t *codepoint)
Decode a UTF-8 sequence to a Unicode codepoint.
Definition utf8.c:28
int extract_ip_from_address(const char *addr_with_port, char *ip_out, size_t ip_out_size)
Extract IP address (without port) from formatted address string.
Definition ip.c:1010
const char * get_ip_type_string(const char *ip)
Get human-readable string describing IP address type.
Definition ip.c:1049
void strip_ansi_codes(const char *input, char *output, size_t output_size)
Strip ANSI escape codes from a string.
int display_center_horizontal(const char *text, int terminal_width)
Calculate left padding needed to center text horizontally.
int display_height(const char *text, int terminal_width)
Calculate how many display lines text will consume when wrapped.
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.
void ui_help_keys(char *out, size_t cap, const char *keys)
Definition help_menu.c:25
bool ui_help_menu_render(frame_buffer_t *out, terminal_size_t size, const ui_help_menu_t *m)
Definition help_menu.c:103
🖥️ Display Width and Terminal Centering Utilities
🌍 IP Address Parsing and Formatting Utilities
std::string escape(const std::string &str)
Escape a string for JSON output.
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
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 * log_search_get_mutex(void)
Get the mutex protecting grep state.
Definition search.c:1031
bool log_search_is_entering(void)
Check if currently in input mode (typing pattern).
Definition search.c:423
void log_search_process_pending(void)
Definition search.c:489
asciichat_error_t log_search_filter_buffer(session_log_buffer_t *log_buf, session_log_entry_t **out_entries, size_t *out_count)
Definition search.c:603
const char * log_search_get_input_buffer(void)
Get current input buffer content (must hold mutex).
Definition search.c:1037
bool log_search_is_active(void)
Check if filtering is active.
Definition search.c:430
bool log_search_get_match_info(const char *message, size_t *out_match_start, size_t *out_match_len)
Get match info for highlighting a log message.
Definition search.c:811
int log_search_get_cursor_position(void)
Get current cursor position in input buffer (must hold mutex).
Definition search.c:1035
Interactive search filtering for terminal screens.
size_t session_log_buffer_get_recent(session_log_buffer_t *buf, session_log_entry_t *out_entries, size_t max_count)
Get recent log entries from buffer.
Thread-safe circular log buffer for session screens (status, splash).
#define SESSION_LOG_BUFFER_SIZE
#define SESSION_LOG_LINE_MAX
void ui_status_render_header(frame_buffer_t *buf, terminal_size_t term_size, void *user_data)
#define TUI_SESSION_STATUS_IPV4_ONLY_BUFFER_SIZE
#define TUI_SESSION_STATUS_ADDR_LINE_TRUNCATED_BUFFER_SIZE
void terminal_screen_compose(frame_buffer_t *output, terminal_size_t size, const terminal_screen_config_t *config, session_log_buffer_t *logs)
#define TUI_SESSION_STATUS_UPTIME_BUFFER_SIZE
#define TUI_SESSION_STATUS_IPV6_ONLY_BUFFER_SIZE
#define TUI_SESSION_STATUS_TEXT_BUFFER_SIZE
#define TUI_SESSION_STATUS_STATUS_LINE_COLORED_BUFFER_SIZE
#define TUI_SESSION_STATUS_ADDR_LINE_BUFFER_SIZE
#define TUI_SESSION_STATUS_STATUS_LINE_BUFFER_SIZE
#define TUI_SESSION_STATUS_FOOTER_BUFFER_SIZE
#define TUI_SESSION_STATUS_KEYS_BUFFER_SIZE
void terminal_screen_logs_render_help(frame_buffer_t *output, terminal_size_t size)
#define TUI_SESSION_STATUS_STATUS_LINE_TRUNCATED_BUFFER_SIZE
bool terminal_should_color_output(int fd, const terminal_options_t *options)
bool terminal_should_use_utf8(terminal_utf8_setting_t user_setting)
📊 Status screen display and management for server/discovery service modes
🔤 String Manipulation and Shell Escaping Utilities
One formatted session log line and its monotonic history sequence.
uint64_t sequence
Sequence number (monotonic, for ordering).
Configuration for terminal screen rendering.
terminal_screen_header_fn render_header
Callback to draw header content.
bool show_logs
Whether to show log feed below header.
bool hide_cursor
Hide cursor while this screen owns the terminal.
void * user_data
Passed to render_header callback.
Definition help_menu.h:7
ui help entry keeps the values that move through the subsystem: keys, description....
Definition help_menu.h:19
Status information for server/discovery service modes.
Definition status.h:43
bool ipv4_bound
Whether IPv4 socket is bound.
Definition status.h:55
char ipv4_address[256]
Definition status.h:47
const char * detail
Optional client controls in the address row.
Definition status.h:59
bool ipv6_bound
Whether IPv6 socket is bound.
Definition status.h:56
char ipv6_address[256]
Definition status.h:50
char session_string[64]
(e.g., "happy-sunset-ocean")
Definition status.h:45
const char * mode_name
Mode name (e.g., "Server", "Discovery Service").
Definition status.h:60
time_t start_time
Server start time (for uptime calculation).
Definition status.h:58
size_t connected_count
Number of connected clients/servers.
Definition status.h:54
bool terminal_screen_logs_help_open(void)
size_t terminal_screen_logs_retain_position(uint64_t tail_sequence, size_t appended_rows, size_t maximum_offset)
uint64_t terminal_screen_logs_last_tail_sequence(void)
bool terminal_screen_logs_help_too_small(void)
Reusable "fixed header + scrolling logs" terminal screen abstraction.
⏱️ High-precision timing utilities using sokol_time.h and uthash
@ UI_SCREEN_SPLASH
size_t utf8_prefix_bytes_for_width(const char *str, size_t max_bytes, int max_width)
Return the byte length of a prefix fitting a terminal column limit.
Definition utf8.c:96
🔤 UTF-8 Encoding and Decoding Utilities