ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
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 24 of file status.h.

◆ TUI_STATUS_IPV6_ADDRESS_BUFFER_SIZE

#define TUI_STATUS_IPV6_ADDRESS_BUFFER_SIZE   256

Definition at line 25 of file status.h.

◆ TUI_STATUS_SESSION_STRING_BUFFER_SIZE

#define TUI_STATUS_SESSION_STRING_BUFFER_SIZE   64

Definition at line 23 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 115 of file status.c.

115 {
116 if (!status) {
117 return;
118 }
119
120 // Only render the status screen if:
121 // 1. Terminal is interactive (default behavior), OR
122 // 2. User explicitly set --status-screen on command line (force it regardless
123 // of terminal) In non-interactive mode without explicit flag, logs flow to
124 // stdout/stderr normally
126 !flags_explicit_state_was_set("status-screen")) {
127 return;
128 }
129
130 // Redirect status screen to stderr when stdout is piped (not a TTY).
131 // This keeps stdout clean for frame data while status goes to stderr.
132 // Uses platform_isatty() so non-desktop platforms (iOS, WASM) can override.
133 if (!platform_isatty(STDOUT_FILENO)) {
134 terminal_screen_set_output_fd(STDERR_FILENO);
135 }
136
137 // If --grep pattern was provided, enter interactive grep mode with it
138 // pre-populated Only do this once (check if not already entering)
139 static bool grep_mode_entered = false;
140 if (!grep_mode_entered && grep_get_last_pattern() &&
141 grep_get_last_pattern()[0] != '\0') {
143 grep_mode_entered = true;
144 }
145
146 // Use terminal_screen abstraction for rendering
147 ui_status_t rendered = *status;
148 if (!rendered.detail)
149 rendered.detail = ui_status_log_controls();
150 terminal_screen_config_t config = {
151 .screen = UI_SCREEN_STATUS,
152 .output_fd =
153 platform_isatty(STDOUT_FILENO) ? STDOUT_FILENO : STDERR_FILENO,
154 .user_data_size = sizeof(*status),
155 .minimum_cols = 20,
156 .fixed_header_lines = 4,
157 .render_header = ui_status_render_header,
158 .user_data = &rendered,
159 .show_logs = true,
160 };
161
162 terminal_screen_render(&config);
163}
const char * grep_get_last_pattern(void)
Get the last (most recent) filter pattern string.
Definition grep.c:1198
void log_search_enter_mode(void)
Enter search mode (user pressed '/').
Definition search.c:233
void ui_status_render_header(frame_buffer_t *buf, terminal_size_t term_size, void *user_data)
bool terminal_is_interactive(void)
const char * ui_status_log_controls(void)
Definition status.c:33
Configuration for terminal screen rendering.
Status information for server/discovery service modes.
Definition status.h:43
const char * detail
Optional client controls in the address row.
Definition status.h:59
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
int platform_isatty(int fd)
Definition util.c:70

References ui_status_t::detail, grep_get_last_pattern(), log_search_enter_mode(), platform_isatty(), terminal_is_interactive(), 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 170 of file status.c.

170 {
171 if (!status) {
172 return true;
173 }
174
175 // Only render the status screen if:
176 // 1. Terminal is interactive (default behavior), OR
177 // 2. User explicitly set --status-screen on command line (force it regardless
178 // of terminal) In non-interactive mode without explicit flag, logs flow to
179 // stdout/stderr normally
181 !flags_explicit_state_was_set("status-screen")) {
182 return true;
183 }
184
185 // If --grep pattern was provided, enter interactive grep mode with it
186 // pre-populated
187 static bool grep_mode_entered = false;
188 if (!grep_mode_entered && grep_get_last_pattern() &&
189 grep_get_last_pattern()[0] != '\0') {
191 grep_mode_entered = true;
192 }
193
194 // Status may use stderr when stdout is redirected. Check the descriptors
195 // used by this screen instead of requiring stdout to be a terminal.
196 int output_fd =
197 platform_isatty(STDOUT_FILENO) ? STDOUT_FILENO : STDERR_FILENO;
198 bool keyboard_enabled = false;
199 if (platform_isatty(STDIN_FILENO) && platform_isatty(output_fd) &&
200 keyboard_init() == ASCIICHAT_OK) {
201 keyboard_enabled = true;
202 }
203
204 // Use terminal_screen abstraction for rendering
205 ui_status_t rendered = *status;
206 if (!rendered.detail)
207 rendered.detail = ui_status_log_controls();
208 terminal_screen_config_t config = {
209 .screen = UI_SCREEN_STATUS,
210 .output_fd = output_fd,
211 .user_data_size = sizeof(*status),
212 .minimum_cols = 20,
213 .fixed_header_lines = 4,
214 .render_header = ui_status_render_header,
215 .user_data = &rendered,
216 .show_logs = true,
217 };
218
219 terminal_screen_render(&config);
220
221 // Poll keyboard for Escape to exit or for interactive grep
222 bool should_exit_status = false;
223 if (keyboard_enabled) {
224 keyboard_key_t key = ui_input_read_key(UI_SCREEN_STATUS);
226 return true;
227 } else if (key == KEY_BACKTICK) {
229 } else if (key == KEY_ESCAPE) {
230 // Escape key: cancel grep if active, otherwise exit status screen
231 if (log_search_is_active()) {
232 log_search_exit_mode(false); // Cancel grep without applying
233 } else {
234 should_exit_status = true; // Exit status screen
235 }
236 } else if (key != KEY_NONE && log_search_should_handle(key)) {
238 }
239 }
240
241 // Keyboard ownership lasts until session shutdown, including between status
242 // frames.
243
244 return !should_exit_status; // Return false if user wants to exit
245}
void ui_errno_stacks_toggle(void)
bool ui_errno_stacks_handle_key(keyboard_key_t key)
@ ASCIICHAT_OK
Definition error_codes.h:50
bool log_search_is_active(void)
Check if filtering is active.
Definition search.c:430
void log_search_exit_mode(bool accept)
Exit search mode.
Definition search.c:312
bool log_search_should_handle(int key)
Check if a key should be handled by grep module.
Definition search.c:441
asciichat_error_t log_search_handle_key(keyboard_key_t key)
Process keyboard input for grep.
Definition search.c:532
keyboard_key_t ui_input_read_key(ui_screen_t screen)
Definition tui/input.c:374

References ASCIICHAT_OK, ui_status_t::detail, grep_get_last_pattern(), log_search_enter_mode(), log_search_exit_mode(), log_search_handle_key(), log_search_is_active(), log_search_should_handle(), platform_isatty(), terminal_is_interactive(), 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 76 of file status.c.

79 {
80 if (!server || !out_status || !mode_name) {
81 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters");
82 }
83
84 memset(out_status, 0, sizeof(*out_status));
85
86 // Copy session string
87 if (session_string) {
88 SAFE_STRNCPY(out_status->session_string, session_string,
89 sizeof(out_status->session_string));
90 }
91
92 // Format IPv4 address
93 out_status->ipv4_bound = (ipv4_address && ipv4_address[0] != '\0');
94 if (out_status->ipv4_bound) {
95 snprintf(out_status->ipv4_address, sizeof(out_status->ipv4_address),
96 "%s:%u", ipv4_address, port);
97 }
98
99 // Format IPv6 address
100 out_status->ipv6_bound = (ipv6_address && ipv6_address[0] != '\0');
101 if (out_status->ipv6_bound) {
102 snprintf(out_status->ipv6_address, sizeof(out_status->ipv6_address),
103 "[%s]:%u", ipv6_address, port);
104 }
105
106 out_status->port = port;
107 out_status->start_time = start_time;
108 out_status->mode_name = mode_name;
109 out_status->session_is_mdns_only = session_is_mdns_only;
111
112 return ASCIICHAT_OK;
113}
#define SET_ERRNO(code,...)
#define SAFE_STRNCPY(dst, src, size)
@ ERROR_INVALID_PARAM
size_t network_server_connection_count(network_server_t *s)
bool ipv4_bound
Whether IPv4 socket is bound.
Definition status.h:55
char ipv4_address[256]
Definition status.h:47
bool ipv6_bound
Whether IPv6 socket is bound.
Definition status.h:56
uint16_t port
TCP listen port.
Definition status.h:53
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
bool session_is_mdns_only
Whether session is mDNS-only or ACDS.
Definition status.h:57
size_t connected_count
Number of connected clients/servers.
Definition status.h:54

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 66 of file status.c.

66 {
67 // Delegate to terminal_screen log abstraction
69}
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 33 of file status.c.

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

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 59 of file status.c.

59 {
60 // Unregister from logger before destroying
62 // Cleanup the shared terminal screen log buffer
64}
void log_clear_session_log_buffer(void)
Unregister the session log buffer.
Definition log/log.c:2272
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 51 of file status.c.

51 {
52 // Initialize the shared terminal screen log buffer
54 if (buf) {
56 }
57}
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/log.c:2263
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.

35 {
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}
@ LOG_COLOR_DEBUG
Definition color.h:8
unsigned char colors[(512 *256 *2) *3]
Definition fft.c:23
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.
#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
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
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.
#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
bool terminal_should_color_output(int fd, const terminal_options_t *options)
bool terminal_should_use_utf8(terminal_utf8_setting_t user_setting)

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, terminal_should_color_output(), terminal_should_use_utf8(), 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 247 of file status.c.

250 {
251 if (!server || !last_update_ns) {
252 return;
253 }
254
255 // Update at FPS rate (60 Hz = 16.67ms by default)
256 uint32_t fps = GET_OPTION(fps);
257 if (fps == 0) {
258 fps = 60; // Default
259 }
260
261 // Calculate frame interval in microseconds
262 uint64_t frame_interval_us = US_PER_SEC_INT / fps;
263
264 // Get current time in microseconds using platform abstraction
265 uint64_t now_us = platform_get_monotonic_time_us();
266
267 // Check if enough time has passed
268 if ((now_us - *last_update_ns) < frame_interval_us) {
269 return; // Too soon, skip frame
270 }
271
272 ui_status_t status;
273 if (ui_status_gather(server, session_string, ipv4_address, ipv6_address, port,
274 start_time, mode_name, session_is_mdns_only,
275 &status) == ASCIICHAT_OK) {
276 ui_status_display(&status);
277 *last_update_ns = now_us;
278 }
279}
unsigned int uint32_t
unsigned long long uint64_t
#define US_PER_SEC_INT
Definition time.h:177
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:76
void ui_status_display(const ui_status_t *status)
Display status screen.
Definition status.c:115

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