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

📊 Status screen display and management for server/discovery service modes More...

Go to the source code of this file.

Data Structures

struct  ui_status_t
 Status information for server/discovery service modes. More...

Macros

#define TUI_STATUS_SESSION_STRING_BUFFER_SIZE   64
#define TUI_STATUS_IPV4_ADDRESS_BUFFER_SIZE   256
#define TUI_STATUS_IPV6_ADDRESS_BUFFER_SIZE   256

Functions

void ui_status_render_header (frame_buffer_t *buffer, terminal_size_t size, void *status)
const char * ui_status_log_controls (void)
asciichat_error_t ui_status_gather (network_server_t *server, const char *session_string, const char *ipv4_address, const char *ipv6_address, uint16_t port, time_t start_time, const char *mode_name, bool session_is_mdns_only, ui_status_t *out_status)
 Gather current status information.
void ui_status_display (const ui_status_t *status)
 Display status screen.
bool ui_status_display_interactive (const ui_status_t *status)
 Display status screen with interactive keyboard support.
void ui_status_update (network_server_t *server, const char *session_string, const char *ipv4_address, const char *ipv6_address, uint16_t port, time_t start_time, const char *mode_name, bool session_is_mdns_only, uint64_t *last_update_ns)
 Periodically update status display with live logs at FPS rate.
void ui_status_log_init (void)
 Initialize status screen log capture system.
void ui_status_log_destroy (void)
 Cleanup status screen log capture system.
void ui_status_log_append (const char *message)
 Append a log message to status screen buffer.
void ui_status_log_clear (void)
 Clear all log messages from status screen buffer.

Detailed Description

📊 Status screen display and management for server/discovery service modes

Manages periodic display of status information including:

  • Session string (memorable 3-word string)
  • Bind addresses (IPv4 and IPv6)
  • Connected client/server count
  • Server uptime

The status screen is updated periodically from the TCP server accept loop via callback and can be disabled with –no-status-screen flag.

Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
February 2026

Definition in file status.h.

Macro Definition Documentation

◆ TUI_STATUS_IPV4_ADDRESS_BUFFER_SIZE

#define TUI_STATUS_IPV4_ADDRESS_BUFFER_SIZE   256

Definition at line 23 of file status.h.

◆ TUI_STATUS_IPV6_ADDRESS_BUFFER_SIZE

#define TUI_STATUS_IPV6_ADDRESS_BUFFER_SIZE   256

Definition at line 24 of file status.h.

◆ TUI_STATUS_SESSION_STRING_BUFFER_SIZE

#define TUI_STATUS_SESSION_STRING_BUFFER_SIZE   64

Definition at line 22 of file status.h.

Function Documentation

◆ ui_status_display()

void ui_status_display ( const ui_status_t * status)

Display status screen.

Outputs formatted status to stdout. Uses ANSI escape codes for clean display that doesn't interfere with logging output.

Parameters
statusStatus information

Definition at line 106 of file status.c.

106 {
107 if (!status) {
108 return;
109 }
110
111 // Only render the status screen if:
112 // 1. Terminal is interactive (default behavior), OR
113 // 2. User explicitly set --status-screen on command line (force it regardless of terminal)
114 // In non-interactive mode without explicit flag, logs flow to stdout/stderr normally
115 if (!terminal_is_interactive() && !GET_OPTION(status_screen_explicitly_set)) {
116 return;
117 }
118
119 // Redirect status screen to stderr when stdout is piped (not a TTY).
120 // This keeps stdout clean for frame data while status goes to stderr.
121 // Uses platform_isatty() so non-desktop platforms (iOS, WASM) can override.
122 if (!platform_isatty(STDOUT_FILENO)) {
123 terminal_screen_set_output_fd(STDERR_FILENO);
124 }
125
126 // If --grep pattern was provided, enter interactive grep mode with it pre-populated
127 // Only do this once (check if not already entering)
128 static bool grep_mode_entered = false;
129 if (!grep_mode_entered && grep_get_last_pattern() && grep_get_last_pattern()[0] != '\0') {
131 grep_mode_entered = true;
132 }
133
134 // Use terminal_screen abstraction for rendering
135 ui_status_t rendered = *status;
136 if (!rendered.detail)
137 rendered.detail = ui_status_log_controls();
138 terminal_screen_config_t config = {
139 .screen = UI_SCREEN_STATUS,
140 .output_fd = platform_isatty(STDOUT_FILENO) ? STDOUT_FILENO : STDERR_FILENO,
141 .user_data_size = sizeof(*status),
142 .minimum_cols = 20,
143 .fixed_header_lines = 4,
144 .render_header = ui_status_render_header,
145 .user_data = &rendered,
146 .show_logs = true,
147 };
148
149 terminal_screen_render(&config);
150}
const char * grep_get_last_pattern(void)
Get the last (most recent) filter pattern string.
Definition grep.c:1135
#define GET_OPTION(field)
Safely get a specific option field (lock-free read).
Definition options.h:1336
void log_search_enter_mode(void)
Enter search mode (user pressed '/').
Definition search.c:226
void ui_status_render_header(frame_buffer_t *buf, terminal_size_t term_size, void *user_data)
const char * ui_status_log_controls(void)
Definition status.c:34
Configuration for terminal screen rendering.
Status information for server/discovery service modes.
Definition status.h:38
const char * detail
Optional client controls in the address row.
Definition status.h:48
void terminal_screen_render(const terminal_screen_config_t *config)
Render a terminal screen with fixed header and scrolling logs.
void terminal_screen_set_output_fd(int fd)
Set output file descriptor for terminal screens (splash/status).
@ UI_SCREEN_STATUS

References ui_status_t::detail, GET_OPTION, grep_get_last_pattern(), log_search_enter_mode(), terminal_screen_render(), terminal_screen_set_output_fd(), UI_SCREEN_STATUS, ui_status_log_controls(), and ui_status_render_header().

Referenced by ui_status_update().

◆ ui_status_display_interactive()

bool ui_status_display_interactive ( const ui_status_t * status)

Display status screen with interactive keyboard support.

Renders status screen and handles keyboard input:

  • Escape cancels grep if active, otherwise exits status screen
  • Other keys handled by interactive grep if active
Parameters
statusStatus information
Returns
true if status screen should continue, false if user pressed Escape to exit

Display status screen with interactive keyboard support.

Definition at line 156 of file status.c.

156 {
157 if (!status) {
158 return true;
159 }
160
161 // Only render the status screen if:
162 // 1. Terminal is interactive (default behavior), OR
163 // 2. User explicitly set --status-screen on command line (force it regardless of terminal)
164 // In non-interactive mode without explicit flag, logs flow to stdout/stderr normally
165 if (!terminal_is_interactive() && !GET_OPTION(status_screen_explicitly_set)) {
166 return true;
167 }
168
169 // If --grep pattern was provided, enter interactive grep mode with it pre-populated
170 static bool grep_mode_entered = false;
171 if (!grep_mode_entered && grep_get_last_pattern() && grep_get_last_pattern()[0] != '\0') {
173 grep_mode_entered = true;
174 }
175
176 // Status may use stderr when stdout is redirected. Check the descriptors
177 // used by this screen instead of requiring stdout to be a terminal.
178 int output_fd = platform_isatty(STDOUT_FILENO) ? STDOUT_FILENO : STDERR_FILENO;
179 bool keyboard_enabled = false;
180 if (platform_isatty(STDIN_FILENO) && platform_isatty(output_fd) && keyboard_init() == ASCIICHAT_OK) {
181 keyboard_enabled = true;
182 }
183
184 // Use terminal_screen abstraction for rendering
185 ui_status_t rendered = *status;
186 if (!rendered.detail)
187 rendered.detail = ui_status_log_controls();
188 terminal_screen_config_t config = {
189 .screen = UI_SCREEN_STATUS,
190 .output_fd = output_fd,
191 .user_data_size = sizeof(*status),
192 .minimum_cols = 20,
193 .fixed_header_lines = 4,
194 .render_header = ui_status_render_header,
195 .user_data = &rendered,
196 .show_logs = true,
197 };
198
199 terminal_screen_render(&config);
200
201 // Poll keyboard for Escape to exit or for interactive grep
202 bool should_exit_status = false;
203 if (keyboard_enabled) {
206 return true;
207 } else if (key == KEY_BACKTICK) {
209 } else if (key == KEY_ESCAPE) {
210 // Escape key: cancel grep if active, otherwise exit status screen
211 if (log_search_is_active()) {
212 log_search_exit_mode(false); // Cancel grep without applying
213 } else {
214 should_exit_status = true; // Exit status screen
215 }
216 } else if (key != KEY_NONE && log_search_should_handle(key)) {
218 }
219 }
220
221 // Keyboard ownership lasts until session shutdown, including between status frames.
222
223 return !should_exit_status; // Return false if user wants to exit
224}
void ui_errno_stacks_toggle(void)
bool ui_errno_stacks_handle_key(keyboard_key_t key)
@ ASCIICHAT_OK
Definition error_codes.h:46
asciichat_error_t keyboard_init(void)
Initialize keyboard input system.
keyboard_key_t
Options for interactive line editing.
Definition keyboard.h:53
@ KEY_BACKTICK
'`' key - print lock state (debug builds)
Definition keyboard.h:84
@ KEY_ESCAPE
Escape key (ESC).
Definition keyboard.h:55
@ KEY_NONE
No key pressed or no input available.
Definition keyboard.h:54
bool log_search_is_active(void)
Check if filtering is active.
Definition search.c:413
void log_search_exit_mode(bool accept)
Exit search mode.
Definition search.c:303
bool log_search_should_handle(int key)
Check if a key should be handled by grep module.
Definition search.c:422
asciichat_error_t log_search_handle_key(keyboard_key_t key)
Process keyboard input for grep.
Definition search.c:508
keyboard_key_t ui_input_read_key(ui_screen_t screen)
Definition tui/input.c:353

References ASCIICHAT_OK, ui_status_t::detail, GET_OPTION, grep_get_last_pattern(), KEY_BACKTICK, KEY_ESCAPE, KEY_NONE, keyboard_init(), log_search_enter_mode(), log_search_exit_mode(), log_search_handle_key(), log_search_is_active(), log_search_should_handle(), terminal_screen_render(), ui_errno_stacks_handle_key(), ui_errno_stacks_toggle(), ui_input_read_key(), UI_SCREEN_STATUS, ui_status_log_controls(), and ui_status_render_header().

◆ ui_status_gather()

asciichat_error_t ui_status_gather ( network_server_t * server,
const char * session_string,
const char * ipv4_address,
const char * ipv6_address,
uint16_t port,
time_t start_time,
const char * mode_name,
bool session_is_mdns_only,
ui_status_t * out_status )

Gather current status information.

Collects current status information including connected count, bind addresses, and session string.

Parameters
serverInitialized TCP server structure
session_stringMemorable session string
ipv4_addressIPv4 bind address (can be NULL or empty)
ipv6_addressIPv6 bind address (can be NULL or empty)
portTCP listen port
start_timeServer start time
mode_nameMode name for display (e.g., "Server")
session_is_mdns_onlyWhether session is mDNS-only or ACDS
[out]out_statusOutput status structure
Returns
ASCIICHAT_OK on success

Definition at line 71 of file status.c.

73 {
74 if (!server || !out_status || !mode_name) {
75 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters");
76 }
77
78 memset(out_status, 0, sizeof(*out_status));
79
80 // Copy session string
81 if (session_string) {
82 SAFE_STRNCPY(out_status->session_string, session_string, sizeof(out_status->session_string));
83 }
84
85 // Format IPv4 address
86 out_status->ipv4_bound = (ipv4_address && ipv4_address[0] != '\0');
87 if (out_status->ipv4_bound) {
88 snprintf(out_status->ipv4_address, sizeof(out_status->ipv4_address), "%s:%u", ipv4_address, port);
89 }
90
91 // Format IPv6 address
92 out_status->ipv6_bound = (ipv6_address && ipv6_address[0] != '\0');
93 if (out_status->ipv6_bound) {
94 snprintf(out_status->ipv6_address, sizeof(out_status->ipv6_address), "[%s]:%u", ipv6_address, port);
95 }
96
97 out_status->port = port;
98 out_status->start_time = start_time;
99 out_status->mode_name = mode_name;
100 out_status->session_is_mdns_only = session_is_mdns_only;
102
103 return ASCIICHAT_OK;
104}
#define SET_ERRNO(code,...)
#define SAFE_STRNCPY(dst, src, size)
Definition common.h:423
@ ERROR_INVALID_PARAM
size_t network_server_connection_count(network_server_t *s)
bool ipv4_bound
Whether IPv4 socket is bound.
Definition status.h:44
char ipv4_address[256]
Formatted IPv4 bind address with port.
Definition status.h:40
bool ipv6_bound
Whether IPv6 socket is bound.
Definition status.h:45
uint16_t port
TCP listen port.
Definition status.h:42
char ipv6_address[256]
Formatted IPv6 bind address with port.
Definition status.h:41
char session_string[64]
Memorable session string (e.g., "happy-sunset-ocean").
Definition status.h:39
const char * mode_name
Mode name (e.g., "Server", "Discovery Service").
Definition status.h:49
time_t start_time
Server start time (for uptime calculation).
Definition status.h:47
bool session_is_mdns_only
Whether session is mDNS-only or ACDS.
Definition status.h:46
size_t connected_count
Number of connected clients/servers.
Definition status.h:43

References ASCIICHAT_OK, ui_status_t::connected_count, ERROR_INVALID_PARAM, ui_status_t::ipv4_address, ui_status_t::ipv4_bound, ui_status_t::ipv6_address, ui_status_t::ipv6_bound, ui_status_t::mode_name, network_server_connection_count(), ui_status_t::port, SAFE_STRNCPY, ui_status_t::session_is_mdns_only, ui_status_t::session_string, SET_ERRNO, and ui_status_t::start_time.

Referenced by ui_status_update().

◆ ui_status_log_append()

void ui_status_log_append ( const char * message)

Append a log message to status screen buffer.

Thread-safe. Called from logging system to capture messages.

Parameters
messageLog message text (already formatted with colors)

◆ ui_status_log_clear()

void ui_status_log_clear ( void )

Clear all log messages from status screen buffer.

Thread-safe. Resets buffer to empty state, discarding all captured logs. Used to clear initialization logs before status screen starts rendering.

Definition at line 62 of file status.c.

62 {
63 // Delegate to terminal_screen log abstraction
65}
void terminal_screen_log_clear(void)
Clear buffered logs for terminal screens.

References terminal_screen_log_clear().

◆ ui_status_log_controls()

const char * ui_status_log_controls ( void )

Shared controls line shown by every interactive log viewer.

Definition at line 34 of file status.c.

34 {
35 static _Thread_local char controls[512];
36 snprintf(controls, sizeof(controls),
37 "%s / %s: close | %s: search logs | %s: keyboard controls | %s / %s: one log | "
38 "%s / %s: page | %s / %s: oldest/newest",
44 return controls;
45}
@ LOG_COLOR_WARN
Definition log/log.h:151
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
Definition string.c:284

References colored_string(), and LOG_COLOR_WARN.

Referenced by ui_session_logs_render(), ui_status_display(), and ui_status_display_interactive().

◆ ui_status_log_destroy()

void ui_status_log_destroy ( void )

Cleanup status screen log capture system.

Call when shutting down. Frees internal log buffer.

Definition at line 55 of file status.c.

55 {
56 // Unregister from logger before destroying
58 // Cleanup the shared terminal screen log buffer
60}
void log_clear_session_log_buffer(void)
Unregister the session log buffer.
Definition log.c:2057
void terminal_screen_log_destroy(void)
Standard log cleanup for terminal screens.

References log_clear_session_log_buffer(), and terminal_screen_log_destroy().

Referenced by session_server_like_run().

◆ ui_status_log_init()

void ui_status_log_init ( void )

Initialize status screen log capture system.

Must be called before using status screen. Creates internal log buffer.

Definition at line 47 of file status.c.

47 {
48 // Initialize the shared terminal screen log buffer
50 if (buf) {
52 }
53}
struct session_log_buffer session_log_buffer_t
Thread-safe fixed-size history ring for session-screen log lines.
void log_set_session_log_buffer(session_log_buffer_t *buf)
Register a session log buffer with the logger.
Definition log.c:2048
session_log_buffer_t * terminal_screen_log_init(void)
Initialize session log buffer for terminal screens.

References log_set_session_log_buffer(), and terminal_screen_log_init().

Referenced by session_server_like_run().

◆ ui_status_render_header()

void ui_status_render_header ( frame_buffer_t * buf,
terminal_size_t term_size,
void * user_data )

The same four-line status header in every host.

Server status presentation shared by native and browser sessions.

Definition at line 34 of file session_status.c.

34 {
35 const ui_status_t *status = (const ui_status_t *)user_data;
36 if (!status) {
37 return;
38 }
39
40 // Calculate uptime
41 time_t now = time(NULL);
42 time_t uptime_secs = now - status->start_time;
43 int uptime_hours = uptime_secs / SEC_PER_HOUR;
44 int uptime_mins = (uptime_secs % SEC_PER_HOUR) / SEC_PER_MIN;
45 int uptime_secs_rem = uptime_secs % 60;
46
47 // Line 1: Top border
48 bool unicode = terminal_should_use_utf8(GET_OPTION(force_utf8));
49 bool colors = !GET_OPTION(strip_ansi) &&
50 terminal_should_color_output(frame_buffer_get_screen_output_fd(), options_terminal_settings());
51 frame_buffer_render_divider(buf, term_size.cols - 1, unicode, colors);
52
53 // The bundled browser font does not contain the emoji used in native status titles.
54#ifdef __EMSCRIPTEN__
55 bool status_icons = false;
56#else
57 bool status_icons = unicode;
58#endif
59
60 // Line 2: Title + Stats (centered)
65 format_uptime_hms(uptime_hours, uptime_mins, uptime_secs_rem, uptime_str, sizeof(uptime_str));
66 bool generic_log_header = status->detail && strstr(status->detail, "keyboard controls") != NULL;
67 if (generic_log_header)
68 snprintf(status_line, sizeof(status_line), status_icons ? "ascii-chat | ⏱️ %s" : "ascii-chat | uptime %s",
69 uptime_str);
70 else if (status->detail)
71 snprintf(status_line, sizeof(status_line), status_icons ? "ascii-chat %s | ⏱️ %s" : "ascii-chat %s | uptime %s",
72 status->mode_name, uptime_str);
73 else
74 snprintf(status_line, sizeof(status_line),
75 status_icons ? "ascii-chat %s | 👥 %zu | ⏱️ %s" : "ascii-chat %s | clients %zu | uptime %s",
76 status->mode_name, status->connected_count, uptime_str);
77
78 // Truncate if needed (ANSI-aware)
79 truncate_with_ellipsis(status_line, status_line_truncated, sizeof(status_line_truncated), term_size.cols - 2);
80 snprintf(status_line_colored, sizeof(status_line_colored), "\033[1m%s\033[0m",
81 colored_string(LOG_COLOR_DEBUG, status_line_truncated));
82
83 int padding = display_center_horizontal(status_line_truncated, term_size.cols);
84 for (int i = 0; i < padding; i++) {
85 frame_buffer_printf(buf, " ");
86 }
87 frame_buffer_printf(buf, "%s\n", status_line_colored);
88
89 // Line 3: Session + Addresses (centered)
90 char addr_line[TUI_SESSION_STATUS_ADDR_LINE_BUFFER_SIZE] = {0};
92 int pos = 0;
93 if (status->session_string[0] != '\0') {
94 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, unicode ? "🔗 %s" : "Session %s", status->session_string);
95 }
96 if (status->ipv4_bound && pos < (int)sizeof(addr_line) - 30) {
97 if (pos > 0) {
98 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, " | ");
99 }
100 // Extract IP and get type
102 if (extract_ip_from_address(status->ipv4_address, ipv4_only, sizeof(ipv4_only)) == 0) {
103 const char *type = get_ip_type_string(ipv4_only);
104 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s (%s)", status->ipv4_address, type);
105 } else {
106 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s", status->ipv4_address);
107 }
108 }
109 if (status->ipv6_bound && pos < (int)sizeof(addr_line) - 30) {
110 if (pos > 0) {
111 pos += snprintf(addr_line + pos, sizeof(addr_line) - pos, " | ");
112 }
113 // Extract IP and get type
115 if (extract_ip_from_address(status->ipv6_address, ipv6_only, sizeof(ipv6_only)) == 0) {
116 const char *type = get_ip_type_string(ipv6_only);
117 snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s (%s)", status->ipv6_address, type);
118 } else {
119 snprintf(addr_line + pos, sizeof(addr_line) - pos, "%s", status->ipv6_address);
120 }
121 }
122
123 if (status->detail)
124 SAFE_STRNCPY(addr_line, status->detail, sizeof(addr_line));
125
126 // Truncate if needed (ANSI-aware)
127 truncate_with_ellipsis(addr_line, addr_line_truncated, sizeof(addr_line_truncated), term_size.cols - 2);
128
129 int addr_padding = display_center_horizontal(addr_line_truncated, term_size.cols);
130 for (int i = 0; i < addr_padding; i++) {
131 frame_buffer_printf(buf, " ");
132 }
133 frame_buffer_printf(buf, "%s\n", addr_line_truncated);
134
135 // Line 4: Bottom border
136 frame_buffer_render_divider(buf, term_size.cols - 1, unicode, colors);
137}
unsigned char colors[(512 *256 *2) *3]
Definition fft.c:22
void frame_buffer_render_divider(frame_buffer_t *buf, int width, bool use_utf8, bool use_colors)
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.
@ LOG_COLOR_DEBUG
Definition log/log.h:149
#define SEC_PER_HOUR
Definition time.h:180
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:318
#define SEC_PER_MIN
Definition time.h:179
#define options_terminal_settings()
Definition options.h:1296
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:972
const char * get_ip_type_string(const char *ip)
Get human-readable string describing IP address type.
Definition ip.c:1010
int display_center_horizontal(const char *text, int terminal_width)
Calculate left padding needed to center text horizontally.
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.
Definition string.c:370
#define TUI_SESSION_STATUS_IPV4_ONLY_BUFFER_SIZE
#define TUI_SESSION_STATUS_ADDR_LINE_TRUNCATED_BUFFER_SIZE
#define TUI_SESSION_STATUS_UPTIME_BUFFER_SIZE
#define TUI_SESSION_STATUS_IPV6_ONLY_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_STATUS_LINE_TRUNCATED_BUFFER_SIZE

References colored_string(), colors, ui_status_t::connected_count, ui_status_t::detail, display_center_horizontal(), extract_ip_from_address(), format_uptime_hms(), frame_buffer_get_screen_output_fd(), frame_buffer_printf(), frame_buffer_render_divider(), get_ip_type_string(), GET_OPTION, ui_status_t::ipv4_address, ui_status_t::ipv4_bound, ui_status_t::ipv6_address, ui_status_t::ipv6_bound, LOG_COLOR_DEBUG, ui_status_t::mode_name, options_terminal_settings, SAFE_STRNCPY, SEC_PER_HOUR, SEC_PER_MIN, ui_status_t::session_string, ui_status_t::start_time, truncate_with_ellipsis(), TUI_SESSION_STATUS_ADDR_LINE_BUFFER_SIZE, TUI_SESSION_STATUS_ADDR_LINE_TRUNCATED_BUFFER_SIZE, TUI_SESSION_STATUS_IPV4_ONLY_BUFFER_SIZE, TUI_SESSION_STATUS_IPV6_ONLY_BUFFER_SIZE, TUI_SESSION_STATUS_STATUS_LINE_BUFFER_SIZE, TUI_SESSION_STATUS_STATUS_LINE_COLORED_BUFFER_SIZE, TUI_SESSION_STATUS_STATUS_LINE_TRUNCATED_BUFFER_SIZE, and TUI_SESSION_STATUS_UPTIME_BUFFER_SIZE.

Referenced by ui_session_logs_render(), ui_status_display(), and ui_status_display_interactive().

◆ ui_status_update()

void ui_status_update ( network_server_t * server,
const char * session_string,
const char * ipv4_address,
const char * ipv6_address,
uint16_t port,
time_t start_time,
const char * mode_name,
bool session_is_mdns_only,
uint64_t * last_update_ns )

Periodically update status display with live logs at FPS rate.

Gathers and displays status with live log feed if enough time has passed since last update (based on GET_OPTION(fps)). Updates at 60 Hz by default.

Parameters
serverInitialized TCP server structure
session_stringMemorable session string
ipv4_addressIPv4 bind address (can be NULL or empty)
ipv6_addressIPv6 bind address (can be NULL or empty)
portTCP listen port
start_timeServer start time
mode_nameMode name for display (e.g., "Server")
session_is_mdns_onlyWhether session is mDNS-only or ACDS
[in,out]last_update_nsLast update time in microseconds (from platform_get_monotonic_time_us)

Definition at line 226 of file status.c.

228 {
229 if (!server || !last_update_ns) {
230 return;
231 }
232
233 // Update at FPS rate (60 Hz = 16.67ms by default)
234 uint32_t fps = GET_OPTION(fps);
235 if (fps == 0) {
236 fps = 60; // Default
237 }
238
239 // Calculate frame interval in microseconds
240 uint64_t frame_interval_us = US_PER_SEC_INT / fps;
241
242 // Get current time in microseconds using platform abstraction
244
245 // Check if enough time has passed
246 if ((now_us - *last_update_ns) < frame_interval_us) {
247 return; // Too soon, skip frame
248 }
249
250 ui_status_t status;
251 if (ui_status_gather(server, session_string, ipv4_address, ipv6_address, port, start_time, mode_name,
252 session_is_mdns_only, &status) == ASCIICHAT_OK) {
253 ui_status_display(&status);
254 *last_update_ns = now_us;
255 }
256}
unsigned int uint32_t
Definition common.h:62
unsigned long long uint64_t
Definition common.h:63
#define US_PER_SEC_INT
Definition time.h:173
uint64_t platform_get_monotonic_time_us(void)
Get monotonic time in microseconds.
asciichat_error_t ui_status_gather(network_server_t *server, const char *session_string, const char *ipv4_address, const char *ipv6_address, uint16_t port, time_t start_time, const char *mode_name, bool session_is_mdns_only, ui_status_t *out_status)
Gather current status information.
Definition status.c:71
void ui_status_display(const ui_status_t *status)
Display status screen.
Definition status.c:106

References ASCIICHAT_OK, GET_OPTION, platform_get_monotonic_time_us(), ui_status_display(), ui_status_gather(), and US_PER_SEC_INT.