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

Go to the source code of this file.

Functions

void invitation_render (frame_buffer_t *buf, terminal_size_t size, const char *session_string, bool joining, int animation_frame, bool use_colors)
void invitation_render_logo (frame_buffer_t *buf, int cols, int animation_frame, bool use_colors, bool compact)

Function Documentation

◆ invitation_render()

void invitation_render ( frame_buffer_t * buf,
terminal_size_t size,
const char * session_string,
bool joining,
int animation_frame,
bool use_colors )

Render the discovery invitation into a frame without writing to the terminal. An empty string shows creation progress; joining shows connection progress. Text is plain ASCII, and the Run instruction immediately follows the string.

Definition at line 58 of file invitation.c.

59 {
60 if (!buf || size.cols < 2 || size.rows < 2)
61 return;
62 int cols = size.cols - 1;
63 int rows = size.rows - 1;
64 bool ready = session && session[0];
65 const char *label =
66 ready ? (joining ? "Connecting to session:" : "Share this string to connect:") : "Creating session...";
67 char command[SESSION_STRING_BUFFER_SIZE + 32];
68 snprintf(command, sizeof(command), "Run: ascii-chat %s", ready ? session : "");
69 const char *lines[3] = {label, ready ? session : "", ready && !joining ? command : ""};
70 int text_rows = 0;
71 for (int i = 0; i < 3; ++i) {
72 if (lines[i][0])
73 text_rows += ((int)strlen(lines[i]) + cols - 1) / cols;
74 }
75 bool compact = cols < 52 || rows < text_rows + 7;
76 int logo_rows = compact ? 1 : 4;
77 bool show_logo = rows >= text_rows + logo_rows + 1;
78 int height = text_rows + (show_logo ? logo_rows + 1 : 0);
79 int top = rows > height ? (rows - height) / 2 : 0;
80 int used = 0;
81 for (; used < top; ++used)
82 frame_buffer_printf(buf, "\n");
83 if (show_logo) {
84 invitation_render_logo(buf, cols, frame, colors, compact);
85 frame_buffer_printf(buf, "\n");
86 used += logo_rows + 1;
87 }
88 // On exceptionally short terminals prioritize the string and its command.
89 int first = height > rows && ready ? 1 : 0;
90 for (int i = first; i < 3 && used < rows; ++i) {
91 const char *text = lines[i];
92 size_t remaining = strlen(text);
93 while (remaining && used < rows) {
94 int length = remaining > (size_t)cols ? cols : (int)remaining;
95 centered_line(buf, text, length, cols, frame, false);
96 text += length;
97 remaining -= length;
98 ++used;
99 }
100 }
101 // Erase stale logs/rows after a layout change without clearing between frames.
102 frame_buffer_printf(buf, "\033[J");
103}
unsigned char colors[(512 *256 *2) *3]
Definition fft.c:22
unsigned int height
Definition fft.c:23
void frame_buffer_printf(frame_buffer_t *buf, const char *fmt,...)
Printf-style append to the buffer.
void invitation_render_logo(frame_buffer_t *buf, int cols, int frame, bool colors, bool compact)
Definition invitation.c:34
#define SESSION_STRING_BUFFER_SIZE

References colors, frame_buffer_printf(), height, invitation_render_logo(), and SESSION_STRING_BUFFER_SIZE.

Referenced by ui_session_splash_render().

◆ invitation_render_logo()

void invitation_render_logo ( frame_buffer_t * buf,
int cols,
int animation_frame,
bool use_colors,
bool compact )

Shared rainbow logo used by the startup splash and discovery invitation.

Definition at line 34 of file invitation.c.

34 {
35 const char *ascii_logo[4] = {
36 " __ _ ___ ___(_|_) ___| |__ __ _| |_ ", " / _` / __|/ __| | |_____ / __| '_ \\ / _` | __| ",
37 "| (_| \\__ \\ (__| | |_____| (__| | | | (_| | |_ ", " \\__,_|___/\\___|_|_| \\___|_| |_|\\__,_|\\__| "};
38 if (compact) {
39 const char *title = "ascii-chat";
40 int len = (int)strlen(title);
41 centered_line(buf, title, len < cols ? len : cols, cols, frame, colors);
42 return;
43 }
44 // Pad every row to the same width so the ASCII glyphs stay aligned.
45 int width = 0;
46 for (int i = 0; i < 4; ++i) {
47 int len = (int)strlen(ascii_logo[i]);
48 if (len > width)
49 width = len;
50 }
51 for (int i = 0; i < 4; ++i) {
53 snprintf(line, sizeof(line), "%-*s", width, ascii_logo[i]);
54 centered_line(buf, line, width < cols ? width : cols, cols, frame, colors);
55 }
56}
unsigned int width
Definition fft.c:23
#define TUI_INVITATION_LINE_BUFFER_SIZE
Definition invitation.c:3

References colors, TUI_INVITATION_LINE_BUFFER_SIZE, and width.

Referenced by invitation_render(), ui_media_panel_render(), ui_session_render(), and ui_session_splash_render().