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.c File Reference

Go to the source code of this file.

Data Structures

struct  ui_session
 This is the handoff point for ui session. Callers fill size, frame, media, logs before passing it on; consumers read the values during the operation and return ownership only where the member contract explicitly says they do. More...

Macros

#define TUI_SESSION_DETAIL_BUFFER_SIZE   256
#define TUI_SESSION_OFFSET_TEXT_BUFFER_SIZE   32
#define PRESENTATION_TIME_HISTORY_COUNT   120

Functions

ui_session_t * ui_session_create (void)
void ui_session_destroy (ui_session_t *s)
void ui_session_resize (ui_session_t *s, int cols, int rows)
void ui_session_loading (ui_session_t *s, bool loading, const char *message)
void ui_session_reconnecting (ui_session_t *s, bool reconnecting, const ui_reconnect_view_t *view)
void ui_session_log (ui_session_t *s, const char *message)
asciichat_error_t ui_session_media (ui_session_t *s, const char *data, size_t length)
ui_session_action_t ui_session_input (ui_session_t *s, keyboard_key_t key)
int ui_session_select_screen (uint32_t visible_screens)
bool ui_session_is_covered (const ui_session_t *s)
size_t ui_session_frame_length (const ui_session_t *s)
uint64_t ui_session_next_frame_ns (const ui_session_t *s)
const char * ui_session_render (ui_session_t *s, const ui_session_view_t *view, uint64_t now_ns)
void ui_session_logs_render (frame_buffer_t *output, terminal_size_t size, ui_session_t *s)
bool ui_session_logs_key (keyboard_key_t key)
const char * ui_session_tick (ui_session_t *s, uint64_t now_ns)
void ui_session_clear (ui_session_t *s)
terminal_size_t ui_session_size (const ui_session_t *s)
void ui_session_redraw (ui_session_t *s)
void ui_session_capture_logs (ui_session_t *s)

Macro Definition Documentation

◆ PRESENTATION_TIME_HISTORY_COUNT

#define PRESENTATION_TIME_HISTORY_COUNT   120

Definition at line 7 of file lib/tui/session.c.

◆ TUI_SESSION_DETAIL_BUFFER_SIZE

#define TUI_SESSION_DETAIL_BUFFER_SIZE   256

Definition at line 3 of file lib/tui/session.c.

Referenced by ui_session_logs_render().

◆ TUI_SESSION_OFFSET_TEXT_BUFFER_SIZE

#define TUI_SESSION_OFFSET_TEXT_BUFFER_SIZE   32

Definition at line 4 of file lib/tui/session.c.

Referenced by ui_session_logs_render().

Function Documentation

◆ ui_session_capture_logs()

void ui_session_capture_logs ( ui_session_t * session)

Attach this instance to the module's existing C logger. Detaches on destruction.

Definition at line 465 of file lib/tui/session.c.

465 {
466 if (s)
468}
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 * logs

References log_set_session_log_buffer(), and ui_session::logs.

Referenced by SessionUiBinding::SessionUiBinding().

◆ ui_session_clear()

void ui_session_clear ( ui_session_t * s)

Definition at line 447 of file lib/tui/session.c.

447 {
448 if (s) {
450 s->help = false;
451 s->show_logs = false;
452 s->dirty = true;
453 }
454}
void frame_buffer_reset(frame_buffer_t *buf)
Clear buffer contents while keeping allocation.
frame_buffer_t * media

References ui_session::dirty, frame_buffer_reset(), ui_session::help, ui_session::media, and ui_session::show_logs.

Referenced by SessionUiBinding::clear().

◆ ui_session_create()

ui_session_t * ui_session_create ( void )

Definition at line 55 of file lib/tui/session.c.

55 {
56 ui_session_t *s = SAFE_CALLOC(1, sizeof(*s), ui_session_t *);
57 if (!s)
58 return NULL;
59 s->frame = frame_buffer_create(24, 80);
60 s->media = frame_buffer_create(24, 80);
62 s->owns_logs = !s->logs;
63 if (s->owns_logs)
65 if (!s->frame || !s->media || !s->logs) {
67 return NULL;
68 }
69 s->started = time(NULL);
71 s->size = (terminal_size_t){.cols = 80, .rows = 24};
72 s->active = -1;
73 s->saved_volume = 1;
74 s->dirty = true;
75 s->splash.use_colors = true;
76 animation_init(&s->animation, "session_splash",
77 (animation_config_t){.type = ANIMATION_SPLASH_RAINBOW,
78 .fps = 60,
79 .speed = 1,
80 .hidden_policy = ANIMATION_HIDDEN_PAUSE});
81 return s;
82}
frame_buffer_t * frame_buffer_create(int rows, int cols)
Create a new frame buffer.
#define SAFE_CALLOC(count, size, cast)
struct ui_session ui_session_t
void ui_session_destroy(ui_session_t *s)
session_log_buffer_t * log_get_history_buffer(void)
Definition log/log.c:625
asciichat_error_t log_search_init(void)
Initialize interactive grep subsystem.
Definition search.c:148
session_log_buffer_t * session_log_buffer_create(void)
Create a new session log buffer instance.
frame_buffer_t * frame
ui_splash_view_t splash
animation_t animation
terminal_size_t size
double saved_volume
asciichat_error_t animation_init(animation_t *a, const char *name, animation_config_t config)

References ui_session::active, ui_session::animation, animation_init(), ui_session::dirty, ui_session::frame, frame_buffer_create(), log_get_history_buffer(), log_search_init(), ui_session::logs, ui_session::media, ui_session::owns_logs, SAFE_CALLOC, ui_session::saved_volume, session_log_buffer_create(), ui_session::size, ui_session::splash, ui_session::started, ui_session_destroy(), and ui_splash_view_t::use_colors.

Referenced by SessionUiBinding::SessionUiBinding().

◆ ui_session_destroy()

void ui_session_destroy ( ui_session_t * s)

Definition at line 84 of file lib/tui/session.c.

84 {
85 if (!s)
86 return;
92 if (s->owns_logs)
94 SAFE_FREE(s);
95}
void frame_buffer_destroy(frame_buffer_t *buf)
Destroy a frame buffer.
#define SAFE_FREE(ptr)
session_log_buffer_t * log_get_session_log_buffer(void)
Get the currently registered session log buffer.
Definition log/log.c:2287
void log_clear_session_log_buffer(void)
Unregister the session log buffer.
Definition log/log.c:2272
void session_log_buffer_destroy(session_log_buffer_t *buf)
Cleanup session log buffer instance.
void animation_destroy(animation_t *a)

References ui_session::animation, animation_destroy(), ui_session::frame, frame_buffer_destroy(), log_clear_session_log_buffer(), log_get_session_log_buffer(), ui_session::logs, ui_session::media, ui_session::owns_logs, SAFE_FREE, and session_log_buffer_destroy().

Referenced by SessionUiBinding::close(), ui_controller_shutdown(), and ui_session_create().

◆ ui_session_frame_length()

size_t ui_session_frame_length ( const ui_session_t * s)

Definition at line 214 of file lib/tui/session.c.

214 {
215 size_t length = s ? frame_buffer_get_length(s->frame) : 0;
216 return length ? length - 1 : 0;
217}
size_t frame_buffer_get_length(const frame_buffer_t *buf)
Get the current content length of the frame buffer.

References ui_session::frame, and frame_buffer_get_length().

◆ ui_session_input()

ui_session_action_t ui_session_input ( ui_session_t * s,
keyboard_key_t key )

Definition at line 177 of file lib/tui/session.c.

177 {
178 if (!s)
179 return UI_ACTION_NONE;
180 if (s->show_logs && ui_session_logs_key_sized(key, s->size)) {
181 s->dirty = true;
182 return UI_ACTION_LOGS;
183 }
184 bool retry = s->active == UI_SCREEN_RECONNECT && s->reconnect.can_retry &&
185 (key == 'r' || key == 'R');
187 retry ? UI_ACTION_RETRY : ui_session_key(key, &s->saved_volume);
188 if (action == UI_ACTION_HELP) {
189 s->help = !s->help;
190 s->show_logs = false;
191 } else if (action == UI_ACTION_LOGS) {
192 s->show_logs = !s->show_logs;
193 s->help = false;
194 } else if (action == UI_ACTION_CLOSE && s->show_logs) {
195 s->show_logs = false;
197 } else if (action == UI_ACTION_CLOSE && s->help) {
198 s->help = false;
200 }
201 s->dirty |= action != UI_ACTION_NONE;
202 return action;
203}
deferred_action_t action
ui_session_action_t ui_session_key(keyboard_key_t key, double *saved_volume)
bool can_retry
The host can immediately start the next attempt.
Definition reconnect.h:32
ui_reconnect_view_t reconnect
@ UI_SCREEN_RECONNECT

References action, ui_session::active, ui_reconnect_view_t::can_retry, ui_session::dirty, ui_session::help, ui_session::reconnect, ui_session::saved_volume, ui_session::show_logs, ui_session::size, UI_ACTION_CLOSE, UI_ACTION_HELP, UI_ACTION_LOGS, UI_ACTION_NONE, UI_ACTION_RETRY, UI_SCREEN_RECONNECT, and ui_session_key().

Referenced by SessionUiBinding::key().

◆ ui_session_is_covered()

bool ui_session_is_covered ( const ui_session_t * s)

Definition at line 212 of file lib/tui/session.c.

212{ return s && s->covered; }

References ui_session::covered.

◆ ui_session_loading()

void ui_session_loading ( ui_session_t * s,
bool loading,
const char * message )

Definition at line 109 of file lib/tui/session.c.

109 {
110 if (!s)
111 return;
112 if (loading != s->loading) {
113 s->loading = loading;
115 s->dirty = true;
116 }
117 if (message && strcmp(message, s->splash.connection_target)) {
119 sizeof(s->splash.connection_target));
120 s->dirty = true;
121 }
122}
#define SAFE_STRNCPY(dst, src, size)
void animation_reset(animation_t *a)

References ui_session::animation, animation_reset(), ui_splash_view_t::connection_target, ui_session::dirty, ui_session::loading, SAFE_STRNCPY, and ui_session::splash.

Referenced by SessionUiBinding::loading().

◆ ui_session_log()

void ui_session_log ( ui_session_t * s,
const char * message )

Definition at line 158 of file lib/tui/session.c.

158 {
159 if (s && message) {
160 session_log_buffer_append(s->logs, message);
161 s->dirty = true;
162 }
163}
void session_log_buffer_append(session_log_buffer_t *buf, const char *message)
Append a log message to the buffer.

References ui_session::dirty, ui_session::logs, and session_log_buffer_append().

Referenced by SessionUiBinding::log().

◆ ui_session_logs_key()

bool ui_session_logs_key ( keyboard_key_t key)

Existing server log-search controls; true when consumed.

Definition at line 381 of file lib/tui/session.c.

381 {
382 return ui_session_logs_key_sized(key, ui_controller_size());
383}
terminal_size_t ui_controller_size(void)

References ui_controller_size().

◆ ui_session_logs_render()

void ui_session_logs_render ( frame_buffer_t * output,
terminal_size_t size,
ui_session_t * session )

Shared live log view, used by the native adapter and browser compositor.

Definition at line 322 of file lib/tui/session.c.

323 {
325 size_t offset = terminal_screen_logs_offset();
326 char offset_text[TUI_SESSION_OFFSET_TEXT_BUFFER_SIZE];
327 snprintf(offset_text, sizeof(offset_text), "%zu", offset);
328 const char *colored_offset = colored_string(LOG_COLOR_FATAL, offset_text);
329 snprintf(detail, sizeof(detail), "%s | %s rows from tail",
330 ui_status_log_controls(), colored_offset);
331 ui_status_t status = {
332 .mode_name = "", .start_time = s->started, .detail = detail};
333 terminal_screen_config_t config = {.fixed_header_lines = 4,
334 .render_header = ui_status_render_header,
335 .user_data = &status,
336 .show_logs = true};
337 terminal_screen_compose(output, size, &config, s->logs);
338}
@ LOG_COLOR_FATAL
Definition color.h:12
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
#define TUI_SESSION_DETAIL_BUFFER_SIZE
#define TUI_SESSION_OFFSET_TEXT_BUFFER_SIZE
void ui_status_render_header(frame_buffer_t *buf, terminal_size_t term_size, void *user_data)
void terminal_screen_compose(frame_buffer_t *output, terminal_size_t size, const terminal_screen_config_t *config, session_log_buffer_t *logs)
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
size_t terminal_screen_logs_offset(void)

References colored_string(), LOG_COLOR_FATAL, ui_session::logs, ui_session::started, terminal_screen_compose(), terminal_screen_logs_offset(), TUI_SESSION_DETAIL_BUFFER_SIZE, TUI_SESSION_OFFSET_TEXT_BUFFER_SIZE, ui_status_log_controls(), and ui_status_render_header().

◆ ui_session_media()

asciichat_error_t ui_session_media ( ui_session_t * s,
const char * data,
size_t length )

Definition at line 165 of file lib/tui/session.c.

166 {
167 if (!s || !data || length > UI_CONTROLLER_MAX_FRAME_BYTES)
168 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid session media frame");
170 frame_buffer_append(s->media, data, length);
171 s->dirty = true;
172 return ASCIICHAT_OK;
173}
#define SET_ERRNO(code,...)
void frame_buffer_append(frame_buffer_t *buf, const char *str, size_t len)
Append raw bytes to the buffer.
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define UI_CONTROLLER_MAX_FRAME_BYTES

References ASCIICHAT_OK, ui_session::dirty, ERROR_INVALID_PARAM, frame_buffer_append(), frame_buffer_reset(), ui_session::media, SET_ERRNO, and UI_CONTROLLER_MAX_FRAME_BYTES.

Referenced by SessionUiBinding::media().

◆ ui_session_next_frame_ns()

uint64_t ui_session_next_frame_ns ( const ui_session_t * session)

Next visible animation deadline, or UINT64_MAX while animation is paused/hidden.

Definition at line 219 of file lib/tui/session.c.

219 {
221 : UINT64_MAX;
222}

References ui_session::animation, ui_splash_view_t::animation, animation_sample_t::next_frame_ns, ui_session::splash, and animation_t::started.

◆ ui_session_reconnecting()

void ui_session_reconnecting ( ui_session_t * session,
bool reconnecting,
const ui_reconnect_view_t * view )

Show the independent reconnect view while the host continues retrying.

Definition at line 124 of file lib/tui/session.c.

125 {
126 if (!s)
127 return;
128 s->reconnecting = reconnecting;
129 if (view) {
130 SAFE_STRNCPY(s->reconnect_target, view->target ? view->target : "server",
131 sizeof(s->reconnect_target));
133 view->transport ? view->transport : "LOST",
134 sizeof(s->reconnect_transport));
136 view->encryption ? view->encryption : "WAITING",
137 sizeof(s->reconnect_encryption));
139 view->handshake ? view->handshake : "WAITING",
140 sizeof(s->reconnect_handshake));
142 view->protocol ? view->protocol : "WAITING",
143 sizeof(s->reconnect_protocol));
145 view->last_error ? view->last_error : "connection closed",
146 sizeof(s->reconnect_error));
147 s->reconnect = *view;
154 }
155 s->dirty = true;
156}
const char * last_error
Definition reconnect.h:27
const char * encryption
Definition reconnect.h:24
const char * protocol
Definition reconnect.h:26
const char * transport
Definition reconnect.h:23
const char * target
Definition reconnect.h:22
const char * handshake
Definition reconnect.h:25
char reconnect_encryption[UI_RECONNECT_DETAIL_BUFFER_SIZE]
char reconnect_target[UI_RECONNECT_TARGET_BUFFER_SIZE]
char reconnect_protocol[UI_RECONNECT_DETAIL_BUFFER_SIZE]
char reconnect_transport[UI_RECONNECT_DETAIL_BUFFER_SIZE]
char reconnect_handshake[UI_RECONNECT_DETAIL_BUFFER_SIZE]
char reconnect_error[UI_RECONNECT_DETAIL_BUFFER_SIZE]

References ui_session::dirty, ui_reconnect_view_t::encryption, ui_reconnect_view_t::handshake, ui_reconnect_view_t::last_error, ui_reconnect_view_t::protocol, ui_session::reconnect, ui_session::reconnect_encryption, ui_session::reconnect_error, ui_session::reconnect_handshake, ui_session::reconnect_protocol, ui_session::reconnect_target, ui_session::reconnect_transport, ui_session::reconnecting, SAFE_STRNCPY, ui_reconnect_view_t::target, and ui_reconnect_view_t::transport.

Referenced by SessionUiBinding::reconnecting().

◆ ui_session_redraw()

void ui_session_redraw ( ui_session_t * s)

Definition at line 460 of file lib/tui/session.c.

460 {
461 if (s)
462 s->dirty = true;
463}

References ui_session::dirty.

Referenced by SessionUiBinding::redraw(), and ui_controller_redraw().

◆ ui_session_render()

const char * ui_session_render ( ui_session_t * session,
const ui_session_view_t * view,
uint64_t now_ns )

Present a host view through the same compositor used by ui_session_tick(). A screen of -1 hides presentation. NULL means no redraw is required.

Definition at line 224 of file lib/tui/session.c.

225 {
226 if (!s || !view)
227 return NULL;
228 bool changed = s->active != view->screen;
229 s->active = view->screen;
230 bool covered = view->screen >= 0 && ui_too_small(s->size, view->minimum);
231 bool transition = changed || covered != s->covered ||
232 s->size.cols != s->presented_size.cols ||
233 s->size.rows != s->presented_size.rows ||
234 view->minimum.cols != s->minimum.cols ||
235 view->minimum.rows != s->minimum.rows;
236 s->covered = covered;
237 bool visible =
238 (view->screen == UI_SCREEN_SPLASH ||
239 view->screen == UI_SCREEN_RECONNECT || view->screen == UI_SCREEN_HELP ||
240 view->screen == UI_SCREEN_MDNS) &&
241 !covered;
242 if (visible != s->animation.visible) {
243 // Account for the elapsed interval under the old visibility before changing
244 // it, so resuming after an idle modal does not advance a paused animation.
245 if (animation_update(&s->animation, now_ns, &s->splash.animation) !=
247 return NULL;
248 animation_set_visible(&s->animation, visible);
249 }
250 if (animation_update(&s->animation, now_ns, &s->splash.animation) !=
252 return NULL;
253 if (view->screen < 0 || !view->draw)
254 return NULL;
255 bool animated = visible && s->splash.animation.changed;
256 bool refresh =
257 view->refresh_ns && now_ns - s->last_render_ns >= view->refresh_ns;
258 if (covered ? !(transition || s->dirty)
259 : !(transition || s->dirty || view->dirty || animated || refresh))
260 return NULL;
261 s->dirty = false;
262 s->presented_size = s->size;
263 s->minimum = view->minimum;
264 s->last_render_ns = now_ns;
266 if (transition || view->clear) {
267 frame_buffer_append(s->frame, "\033[0m", 4);
269 }
270 if (covered)
271 ui_too_small_render(s->frame, s->size, view->minimum);
272 else {
273 // Hide the cursor in the submitted media frame, before moving it to draw
274 // the art. A separate stdout write can be reordered against presentation,
275 // and cached visibility becomes stale when another screen shows the cursor.
276 if (view->screen == UI_SCREEN_MEDIA)
277 frame_buffer_append(s->frame, "\033[?25l", 6);
278 if (view->screen == UI_SCREEN_HELP) {
279 int top = (s->size.rows - view->minimum.rows) / 2;
280 terminal_color_mode_t mode = GET_OPTION(color_mode);
281 bool colors = mode != TERM_COLOR_NONE &&
283 !GET_OPTION(strip_ansi) &&
284 (mode != TERM_COLOR_AUTO ||
286 .color_level != TERM_COLOR_NONE);
287 frame_buffer_printf(s->frame, "\033[%d;1H", top + 2);
289 (int)(s->splash.animation.seconds * 60), colors,
290 false);
291 }
292 view->draw(s->frame, s->size, &s->splash.animation, view->context);
293 }
294 frame_buffer_append(s->frame, "\0", 1);
296}
int color_mode
Definition fft.c:26
unsigned char colors[(512 *256 *2) *3]
Definition fft.c:23
const char * frame_buffer_get_content(const frame_buffer_t *buf)
Get a pointer to the buffer content.
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).
#define GET_OPTION(field)
Definition options.h:1339
#define options_terminal_settings()
Definition options.h:1287
@ COLOR_SETTING_FALSE
Force colors OFF: disable all colors and logging colors.
Definition options.h:250
void invitation_render_logo(frame_buffer_t *buf, int cols, int frame, bool colors, bool compact)
Definition invitation.c:45
terminal_capabilities_t detect_terminal_capabilities(const terminal_options_t *options)
uint64_t last_render_ns
terminal_size_t minimum
terminal_size_t presented_size
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
@ UI_SCREEN_MEDIA
@ UI_SCREEN_SPLASH
@ UI_SCREEN_MDNS
@ UI_SCREEN_HELP
asciichat_error_t animation_update(animation_t *a, uint64_t now, animation_sample_t *out)
void animation_set_visible(animation_t *a, bool visible)

References ui_session::active, ui_session::animation, ui_splash_view_t::animation, animation_set_visible(), animation_update(), ASCIICHAT_OK, animation_sample_t::changed, ui_session_view_t::clear, color_mode, COLOR_SETTING_FALSE, colors, ui_session_view_t::context, ui_session::covered, detect_terminal_capabilities(), ui_session::dirty, ui_session_view_t::dirty, ui_session_view_t::draw, ui_session::frame, frame_buffer_append(), frame_buffer_clear_screen(), frame_buffer_get_content(), frame_buffer_printf(), frame_buffer_reset(), GET_OPTION, invitation_render_logo(), ui_session::last_render_ns, ui_session::minimum, ui_session_view_t::minimum, options_terminal_settings, ui_session::presented_size, ui_session_view_t::refresh_ns, ui_session_view_t::screen, animation_sample_t::seconds, ui_session::size, ui_session::splash, UI_SCREEN_HELP, UI_SCREEN_MDNS, UI_SCREEN_MEDIA, UI_SCREEN_RECONNECT, UI_SCREEN_SPLASH, ui_too_small(), ui_too_small_render(), and animation_t::visible.

Referenced by ui_session_tick().

◆ ui_session_resize()

void ui_session_resize ( ui_session_t * s,
int cols,
int rows )

Definition at line 97 of file lib/tui/session.c.

97 {
98 if (!s || cols < 1 || rows < 1 || cols > 4096 || rows > 4096) {
100 "Invalid TUI session or terminal dimensions");
101 return;
102 }
103 if (cols != s->size.cols || rows != s->size.rows) {
104 s->size = (terminal_size_t){.cols = cols, .rows = rows};
105 s->dirty = true;
106 }
107}

References ui_session::dirty, ERROR_INVALID_PARAM, SET_ERRNO, and ui_session::size.

Referenced by SessionUiBinding::resize().

◆ ui_session_select_screen()

int ui_session_select_screen ( uint32_t visible_screens)

Highest visible screen from the common priority order, or -1.

Definition at line 205 of file lib/tui/session.c.

205 {
206 for (int screen = UI_SCREEN_COUNT - 1; screen >= 0; --screen)
207 if (visible_screens & (1u << screen))
208 return screen;
209 return -1;
210}
@ UI_SCREEN_COUNT

References UI_SCREEN_COUNT.

Referenced by ui_session_tick().

◆ ui_session_size()

terminal_size_t ui_session_size ( const ui_session_t * s)

Definition at line 456 of file lib/tui/session.c.

456 {
457 return s ? s->size : (terminal_size_t){.cols = 80, .rows = 24};
458}

References ui_session::size.

Referenced by ui_controller_size().

◆ ui_session_tick()

const char * ui_session_tick ( ui_session_t * session,
uint64_t now_ns )

No sleeps or I/O. Returned frame remains valid until the next call. NULL means unchanged.

Definition at line 400 of file lib/tui/session.c.

400 {
401 if (!s)
402 return NULL;
403 if (!s->dirty && !s->show_logs && !s->help && !s->loading &&
405 return NULL;
406 uint32_t visible = 1u << UI_SCREEN_MEDIA;
407 if (s->loading)
408 visible |= 1u << UI_SCREEN_SPLASH;
409 if (s->reconnecting)
410 visible |= 1u << UI_SCREEN_RECONNECT;
411 if (s->show_logs)
412 visible |= 1u << UI_SCREEN_LOGS;
413 if (s->help)
414 visible |= 1u << UI_SCREEN_HELP;
415 ui_session_view_t view = {.screen = ui_session_select_screen(visible),
416 .minimum = {1, 1},
417 .clear = !s->help,
418 .context = s};
419 char *help = NULL;
420 if (view.screen == UI_SCREEN_HELP) {
421 help = ui_session_help_render(s->size, true, true, &view.minimum);
422 if (!help)
423 return NULL;
424 view.draw = draw_help;
425 view.context = help;
426 } else if (view.screen == UI_SCREEN_LOGS) {
427 view.minimum = (terminal_size_t){.cols = 40, .rows = 6};
428 view.refresh_ns = 100000000;
429 view.draw = draw_logs;
430 } else if (view.screen == UI_SCREEN_SPLASH) {
431 view.minimum = (terminal_size_t){.cols = 52, .rows = 10};
432 view.draw = draw_splash;
433 } else if (view.screen == UI_SCREEN_RECONNECT) {
435 view.refresh_ns = 125000000;
436 view.draw = draw_reconnect;
437 } else {
438 view.draw = draw_media;
439 if (s->dirty && frame_buffer_get_length(s->media))
440 s->presentation_times[s->presentation_index++ % 120] = now_ns;
441 }
442 const char *frame = ui_session_render(s, &view, now_ns);
444 return frame;
445}
unsigned int uint32_t
int ui_session_select_screen(uint32_t visible_screens)
const char * ui_session_render(ui_session_t *s, const ui_session_view_t *view, uint64_t now_ns)
terminal_size_t ui_reconnect_minimum(void)
Definition reconnect.c:240
void ui_session_help_free(char *text)
char * ui_session_help_render(terminal_size_t size, bool has_media, bool browser, terminal_size_t *minimum)
uint64_t presentation_times[120]
unsigned presentation_index
@ UI_SCREEN_LOGS

References ui_session::active, ui_session_view_t::context, ui_session::dirty, ui_session_view_t::draw, frame_buffer_get_length(), ui_session::help, ui_session::loading, ui_session::media, ui_session_view_t::minimum, ui_session::presentation_index, ui_session::presentation_times, ui_session::reconnecting, ui_session_view_t::refresh_ns, ui_session_view_t::screen, ui_session::show_logs, ui_session::size, ui_reconnect_minimum(), UI_SCREEN_HELP, UI_SCREEN_LOGS, UI_SCREEN_MEDIA, UI_SCREEN_RECONNECT, UI_SCREEN_SPLASH, ui_session_help_free(), ui_session_help_render(), ui_session_render(), and ui_session_select_screen().

Referenced by SessionUiBinding::tick().