ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
invitation.c File Reference

Go to the source code of this file.

Macros

#define TUI_INVITATION_LINE_BUFFER_SIZE   80

Functions

void invitation_render_logo (frame_buffer_t *buf, int cols, int frame, bool colors, bool compact)
void invitation_render_rainbow_clouds (frame_buffer_t *buf, int cols, int frame, bool colors, bool unicode)
void invitation_render (frame_buffer_t *buf, terminal_size_t size, const char *session, bool joining, int frame, bool colors)

Macro Definition Documentation

◆ TUI_INVITATION_LINE_BUFFER_SIZE

#define TUI_INVITATION_LINE_BUFFER_SIZE   80

Definition at line 3 of file invitation.c.

Referenced by invitation_render_logo().

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 79 of file invitation.c.

81 {
82 if (!buf || size.cols < 2 || size.rows < 2)
83 return;
84 int cols = size.cols - 1;
85 int rows = size.rows - 1;
86 bool ready = session && session[0];
87 const char *label = ready ? (joining ? "Connecting to session:"
88 : "Share this string to connect:")
89 : "Creating session...";
90 char command[SESSION_STRING_BUFFER_SIZE + 32];
91 snprintf(command, sizeof(command), "Run: ascii-chat %s",
92 ready ? session : "");
93 const char *lines[3] = {label, ready ? session : "",
94 ready && !joining ? command : ""};
95 int text_rows = 0;
96 for (int i = 0; i < 3; ++i) {
97 if (lines[i][0])
98 text_rows += ((int)strlen(lines[i]) + cols - 1) / cols;
99 }
100 bool compact = cols < 52 || rows < text_rows + 7;
101 int logo_rows = compact ? 1 : 4;
102 bool show_logo = rows >= text_rows + logo_rows + 1;
103 int height = text_rows + (show_logo ? logo_rows + 1 : 0);
104 int top = rows > height ? (rows - height) / 2 : 0;
105 int used = 0;
106 for (; used < top; ++used)
107 frame_buffer_printf(buf, "\n");
108 if (show_logo) {
109 invitation_render_logo(buf, cols, frame, colors, compact);
110 frame_buffer_printf(buf, "\n");
111 used += logo_rows + 1;
112 }
113 // On exceptionally short terminals prioritize the string and its command.
114 int first = height > rows && ready ? 1 : 0;
115 for (int i = first; i < 3 && used < rows; ++i) {
116 const char *text = lines[i];
117 size_t remaining = strlen(text);
118 while (remaining && used < rows) {
119 int length = remaining > (size_t)cols ? cols : (int)remaining;
120 centered_line(buf, text, length, cols, frame, false);
121 text += length;
122 remaining -= length;
123 ++used;
124 }
125 }
126 // Erase stale logs/rows after a layout change without clearing between
127 // frames.
128 frame_buffer_printf(buf, "\033[J");
129}
unsigned char colors[(512 *256 *2) *3]
Definition fft.c:23
unsigned int height
Definition fft.c:24
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:45
#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 45 of file invitation.c.

46 {
47 const char *ascii_logo[4] = {
48 " __ _ ___ ___(_|_) ___| |__ __ _| |_ ",
49 " / _` / __|/ __| | |_____ / __| '_ \\ / _` | __| ",
50 "| (_| \\__ \\ (__| | |_____| (__| | | | (_| | |_ ",
51 " \\__,_|___/\\___|_|_| \\___|_| |_|\\__,_|\\__| "};
52 if (compact) {
53 const char *title = "ascii-chat";
54 int len = (int)strlen(title);
55 centered_line(buf, title, len < cols ? len : cols, cols, frame, colors);
56 return;
57 }
58 // Pad every row to the same width so the ASCII glyphs stay aligned.
59 int width = 0;
60 for (int i = 0; i < 4; ++i) {
61 int len = (int)strlen(ascii_logo[i]);
62 if (len > width)
63 width = len;
64 }
65 for (int i = 0; i < 4; ++i) {
67 snprintf(line, sizeof(line), "%-*s", width, ascii_logo[i]);
68 centered_line(buf, line, width < cols ? width : cols, cols, frame, colors);
69 }
70}
unsigned int width
Definition fft.c:24
#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_reconnect_render(), ui_session_render(), and ui_session_splash_render().

◆ invitation_render_rainbow_clouds()

void invitation_render_rainbow_clouds ( frame_buffer_t * buf,
int cols,
int animation_frame,
bool use_colors,
bool unicode )

Render a rainbow cloud line used by the reconnect status header.

Definition at line 72 of file invitation.c.

73 {
74 const char *clouds = unicode ? "╭─╮ ╭─╮ ╭─╮" : "(__) (__) (__)";
75 int bytes = (int)strlen(clouds);
76 centered_line(buf, clouds, bytes, cols, frame + 9, colors);
77}

References colors.

Referenced by ui_reconnect_render().