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

Go to the source code of this file.

Macros

#define TUI_SESSION_SPLASH_TAGLINE_WITH_VERSION_BUFFER_SIZE   128
#define TUI_SESSION_SPLASH_PLAIN_TAGLINE_BUFFER_SIZE   512
#define TUI_SESSION_SPLASH_PLAIN_UPDATE_BUFFER_SIZE   1024
#define TUI_SESSION_SPLASH_PLAIN_CONNECTION_BUFFER_SIZE   512

Functions

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

Macro Definition Documentation

◆ TUI_SESSION_SPLASH_PLAIN_CONNECTION_BUFFER_SIZE

#define TUI_SESSION_SPLASH_PLAIN_CONNECTION_BUFFER_SIZE   512

Definition at line 6 of file session_splash.c.

Referenced by ui_session_splash_render().

◆ TUI_SESSION_SPLASH_PLAIN_TAGLINE_BUFFER_SIZE

#define TUI_SESSION_SPLASH_PLAIN_TAGLINE_BUFFER_SIZE   512

Definition at line 4 of file session_splash.c.

Referenced by ui_session_splash_render().

◆ TUI_SESSION_SPLASH_PLAIN_UPDATE_BUFFER_SIZE

#define TUI_SESSION_SPLASH_PLAIN_UPDATE_BUFFER_SIZE   1024

Definition at line 5 of file session_splash.c.

Referenced by ui_session_splash_render().

◆ TUI_SESSION_SPLASH_TAGLINE_WITH_VERSION_BUFFER_SIZE

#define TUI_SESSION_SPLASH_TAGLINE_WITH_VERSION_BUFFER_SIZE   128

Definition at line 3 of file session_splash.c.

Referenced by ui_session_splash_render().

Function Documentation

◆ ui_session_splash_render()

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

Definition at line 19 of file session_splash.c.

20 {
21 const ui_splash_view_t *ctx = (const ui_splash_view_t *)user_data;
22 if (!ctx) {
23 return;
24 }
25 bool unicode = terminal_should_use_utf8(GET_OPTION(force_utf8));
26
27 if (ctx->discovery.enabled) {
28 invitation_render(buf, term_size, ctx->discovery.session_string,
29 ctx->discovery.joining,
30 (int)(ctx->animation.seconds * 60), ctx->use_colors);
31 return;
32 }
33
34 char
36 snprintf(tagline_with_version, sizeof(tagline_with_version),
37 "Video chat in your terminal + %s", ASCII_CHAT_VERSION_STRING);
38 const char *tagline = tagline_with_version;
39 frame_buffer_render_divider(buf, term_size.cols - 1, unicode,
40 ctx->use_colors);
41 invitation_render_logo(buf, term_size.cols - 1,
42 (int)(ctx->animation.seconds * 60), ctx->use_colors,
43 false);
44
45 // Line 6: Tagline (centered, truncated if too long)
47 int tagline_len = (int)strlen(tagline);
48 int tagline_pad = (term_size.cols - tagline_len) / 2;
49 if (tagline_pad < 0) {
50 tagline_pad = 0;
51 }
52
53 int tpos = 0;
54 for (int j = 0; j < tagline_pad && tpos < (int)sizeof(plain_tagline) - 1;
55 j++) {
56 plain_tagline[tpos++] = ' ';
57 }
58 snprintf(plain_tagline + tpos, sizeof(plain_tagline) - tpos, "%s", tagline);
59
60 // Check visible width and truncate if needed
61 int tagline_visible_width = display_width(plain_tagline);
62 if (tagline_visible_width < 0) {
63 tagline_visible_width = (int)strlen(plain_tagline);
64 }
65 if (term_size.cols > 0 && tagline_visible_width >= term_size.cols) {
66 plain_tagline[term_size.cols - 1] = '\0';
67 }
68
69 frame_buffer_printf(buf, "%s\n", plain_tagline);
70
71 // Line 7: Update notification (if available)
72 if (ctx->update_notification[0] != '\0') {
74 int update_len = (int)strlen(ctx->update_notification);
75 int update_pad = (term_size.cols - update_len) / 2;
76 if (update_pad < 0) {
77 update_pad = 0;
78 }
79
80 int upos = 0;
81 for (int j = 0; j < update_pad && upos < (int)sizeof(plain_update) - 1;
82 j++) {
83 plain_update[upos++] = ' ';
84 }
85 snprintf(plain_update + upos, sizeof(plain_update) - upos, "%s",
87
88 // Check visible width and truncate if needed
89 int update_visible_width = display_width(plain_update);
90 if (update_visible_width < 0) {
91 update_visible_width = (int)strlen(plain_update);
92 }
93 if (term_size.cols > 0 && update_visible_width >= term_size.cols) {
94 plain_update[term_size.cols - 1] = '\0';
95 }
96
97 // Print in yellow/warning color
98 frame_buffer_printf(buf, "%s\n",
99 colored_string(LOG_COLOR_WARN, plain_update));
100 }
101
102 // Line 8 (or 7 if no update): Connection target (centered, truncated if too
103 // long)
104 const char *connection_target = ctx->connection_target;
105
107 int connection_len = (int)strlen(connection_target);
108 int connection_pad = (term_size.cols - connection_len) / 2;
109 if (connection_pad < 0) {
110 connection_pad = 0;
111 }
112
113 int cpos = 0;
114 for (int j = 0;
115 j < connection_pad && cpos < (int)sizeof(plain_connection) - 1; j++) {
116 plain_connection[cpos++] = ' ';
117 }
118 snprintf(plain_connection + cpos, sizeof(plain_connection) - cpos, "%s",
119 connection_target);
120
121 // Check visible width and truncate if needed
122 int connection_visible_width = display_width(plain_connection);
123 if (connection_visible_width < 0) {
124 connection_visible_width = (int)strlen(plain_connection);
125 }
126 if (term_size.cols > 0 && connection_visible_width >= term_size.cols) {
127 plain_connection[term_size.cols - 1] = '\0';
128 }
129
130 frame_buffer_printf(buf, "%s\n", plain_connection);
131
133 static const char spin[] = "|/-\\";
134 const char *text = "Checking for updates...";
135 int pad = term_size.cols - (int)strlen(text) - 3;
136 if (pad < 0)
137 pad = 0;
138 frame_buffer_printf(buf, "%*s%c %s\n", pad, "",
139 spin[((int)(ctx->animation.seconds * 8)) % 4], text);
140 }
141
142 // Bottom border
143 frame_buffer_render_divider(buf, term_size.cols - 1, unicode,
144 ctx->use_colors);
145}
@ LOG_COLOR_WARN
Definition color.h:10
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.
#define GET_OPTION(field)
Definition options.h:1339
bool update_banner_is_checking(void)
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
int display_width(const char *text)
Calculate the visible display width of text with ANSI escape codes.
void invitation_render_logo(frame_buffer_t *buf, int cols, int frame, bool colors, bool compact)
Definition invitation.c:45
void invitation_render(frame_buffer_t *buf, terminal_size_t size, const char *session, bool joining, int frame, bool colors)
Definition invitation.c:79
#define TUI_SESSION_SPLASH_PLAIN_CONNECTION_BUFFER_SIZE
#define TUI_SESSION_SPLASH_PLAIN_TAGLINE_BUFFER_SIZE
#define TUI_SESSION_SPLASH_PLAIN_UPDATE_BUFFER_SIZE
#define TUI_SESSION_SPLASH_TAGLINE_WITH_VERSION_BUFFER_SIZE
bool terminal_should_use_utf8(terminal_utf8_setting_t user_setting)

References ui_splash_view_t::animation, colored_string(), ui_splash_view_t::connection_target, ui_splash_view_t::discovery, display_width(), ui_discovery_view_t::enabled, frame_buffer_printf(), frame_buffer_render_divider(), GET_OPTION, invitation_render(), invitation_render_logo(), ui_discovery_view_t::joining, LOG_COLOR_WARN, animation_sample_t::seconds, ui_discovery_view_t::session_string, terminal_should_use_utf8(), TUI_SESSION_SPLASH_PLAIN_CONNECTION_BUFFER_SIZE, TUI_SESSION_SPLASH_PLAIN_TAGLINE_BUFFER_SIZE, TUI_SESSION_SPLASH_PLAIN_UPDATE_BUFFER_SIZE, TUI_SESSION_SPLASH_TAGLINE_WITH_VERSION_BUFFER_SIZE, update_banner_is_checking(), ui_splash_view_t::update_notification, and ui_splash_view_t::use_colors.