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

Go to the source code of this file.

Macros

#define TUI_SESSION_HELP_SETTINGS_COUNT   20
#define TUI_SESSION_HELP_VOLUME_BAR_BUFFER_SIZE   32
#define TUI_SESSION_HELP_KEY_STORAGE_COUNT   40
#define TUI_SESSION_HELP_FOOTER_BUFFER_SIZE   128
#define SESSION_HELP_SETTING_BUFFER_SIZE   256
#define SESSION_HELP_KEY_BUFFER_SIZE   48
#define SESSION_HELP_ENTRY_CAPACITY   40
#define ENABLED_COLOR   LOG_COLOR_INFO /* Green */
#define DISABLED_COLOR   LOG_COLOR_ERROR /* Red */

Functions

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)
char * ui_session_context_help_render (terminal_size_t size, ui_screen_t screen, terminal_size_t *minimum)

Macro Definition Documentation

◆ DISABLED_COLOR

#define DISABLED_COLOR   LOG_COLOR_ERROR /* Red */

Definition at line 31 of file session_help.c.

◆ ENABLED_COLOR

#define ENABLED_COLOR   LOG_COLOR_INFO /* Green */

Definition at line 30 of file session_help.c.

◆ SESSION_HELP_ENTRY_CAPACITY

#define SESSION_HELP_ENTRY_CAPACITY   40

Definition at line 15 of file session_help.c.

Referenced by ui_session_help_render().

◆ SESSION_HELP_KEY_BUFFER_SIZE

#define SESSION_HELP_KEY_BUFFER_SIZE   48

Definition at line 12 of file session_help.c.

Referenced by ui_session_help_render().

◆ SESSION_HELP_SETTING_BUFFER_SIZE

#define SESSION_HELP_SETTING_BUFFER_SIZE   256

Definition at line 9 of file session_help.c.

Referenced by ui_session_help_render().

◆ TUI_SESSION_HELP_FOOTER_BUFFER_SIZE

#define TUI_SESSION_HELP_FOOTER_BUFFER_SIZE   128

Definition at line 6 of file session_help.c.

Referenced by ui_session_context_help_render(), and ui_session_help_render().

◆ TUI_SESSION_HELP_KEY_STORAGE_COUNT

#define TUI_SESSION_HELP_KEY_STORAGE_COUNT   40

Definition at line 5 of file session_help.c.

Referenced by ui_session_help_render().

◆ TUI_SESSION_HELP_SETTINGS_COUNT

#define TUI_SESSION_HELP_SETTINGS_COUNT   20

Definition at line 3 of file session_help.c.

Referenced by ui_session_help_render().

◆ TUI_SESSION_HELP_VOLUME_BAR_BUFFER_SIZE

#define TUI_SESSION_HELP_VOLUME_BAR_BUFFER_SIZE   32

Definition at line 4 of file session_help.c.

Referenced by ui_session_help_render().

Function Documentation

◆ ui_session_context_help_render()

char * ui_session_context_help_render ( terminal_size_t size,
ui_screen_t screen,
terminal_size_t * minimum )

Definition at line 289 of file session_help.c.

290 {
291 if (!minimum) {
292 SET_ERRNO(ERROR_INVALID_PARAM, "Help minimum geometry output is required");
293 return NULL;
294 }
295 static const ui_help_entry_t sync[] = {{"0 / Esc", "Close sync viewer"},
296 {"Up / Down", "Select primitive"},
297 {"Left / Right", "Previous/next page"},
298 {"Home / End", "First/last primitive"},
299 {"=", "Running app statistics"},
300 {"]", "Log viewer"},
301 {"?", "Close this help"}};
302 static const ui_help_entry_t stats[] = {
303 {"= / Esc", "Close statistics"},
304 {"Tab / Left / Right", "Switch data page"},
305 {"Up / Down", "Select and scroll rows"},
306 {"Home / End", "First/last row"},
307 {"0", "Sync primitives"},
308 {"]", "Log viewer"},
309 {"?", "Close this help"}};
310 static const ui_help_entry_t errors[] = {
311 {"` / Esc", "Close error stacks"},
312 {"Tab", "Current/history page"},
313 {"Up / Down", "Select and scroll errors"},
314 {"s", "Change sort order"},
315 {"x", "Clear selected error"},
316 {"=", "Running app statistics"},
317 {"0", "Sync primitives"},
318 {"?", "Close this help"}};
319 static const ui_help_entry_t update[] = {
320 {"F12 / Esc", "Close update checker"},
321 {"Left / Right / Tab", "Select button"},
322 {"Enter", "Activate selected button"},
323 {"O", "Open release page"},
324 {"R", "Check again"},
325 {"?", "Close this help"}};
326 static const ui_help_entry_t lan[] = {
327 {"Up / Down / j / k", "Select LAN server"},
328 {"0-9", "Enter server number"},
329 {"Enter", "Connect to selected server"},
330 {"Esc", "Cancel LAN selection"},
331 {"=", "Running app statistics"},
332 {"0", "Sync primitives"},
333 {"?", "Close this help"}};
334 static const ui_help_entry_t media[] = {
335 {"Enter", "Play the entered paths or URLs"},
336 {"Esc / Ctrl-O", "Cancel media input"},
337 {"Left / Right", "Move the text cursor"},
338 {"Home / End", "Beginning/end of input"},
339 {"Backspace / Delete", "Delete a character"},
340 {"?", "Help when the input is empty"}};
341 const ui_help_entry_t *entries = NULL;
342 size_t count = 0;
343 const char *title = NULL;
344 switch (screen) {
345 case UI_SCREEN_ERROR: {
346 static const ui_help_entry_t popup[] = {
347 {"Left / Right", "Previous / next error"},
348 {"Home / End", "First / last error"},
349 {"Up / Down", "Scroll error details"},
350 {"PgUp / PgDn", "Scroll a page"},
351 {"Enter / Esc", "Dismiss all errors"},
352 {"q", "Dismiss all errors"},
353 {"?", "Close this help"}};
354 entries = popup;
355 count = sizeof(popup) / sizeof(*popup);
356 title = "Error Popup Keyboard Shortcuts";
357 break;
358 }
359 case UI_SCREEN_SYNC:
360 entries = sync;
361 count = sizeof(sync) / sizeof(*sync);
362 title = "Sync Viewer Keyboard Shortcuts";
363 break;
364 case UI_SCREEN_STATS:
365 entries = stats;
366 count = sizeof(stats) / sizeof(*stats);
367 title = "Statistics Keyboard Shortcuts";
368 break;
369 case UI_SCREEN_ERRNO:
370 entries = errors;
371 count = sizeof(errors) / sizeof(*errors);
372 title = "Error Stacks Keyboard Shortcuts";
373 break;
374 case UI_SCREEN_PROMPT:
375 entries = media;
376 count = sizeof(media) / sizeof(*media);
377 title = "Media Input Keyboard Shortcuts";
378 break;
379 case UI_SCREEN_MDNS:
380 entries = lan;
381 count = sizeof(lan) / sizeof(*lan);
382 title = "LAN Selection Keyboard Shortcuts";
383 break;
384 case UI_SCREEN_UPDATE:
385 entries = update;
386 count = sizeof(update) / sizeof(*update);
387 title = "Update Checker Keyboard Shortcuts";
388 break;
389 default:
391 size, GET_OPTION(media_file)[0] || GET_OPTION(media_url)[0], false,
392 minimum);
393 }
395 snprintf(footer, sizeof(footer), "Press %s to close",
397 ui_help_menu_t menu = {.title = title,
398 .entries = entries,
399 .count = count,
400 .footer = footer,
401 .top_margin = 0};
402 *minimum = ui_help_menu_measure(&menu);
403 frame_buffer_t *buffer = frame_buffer_create(size.rows, size.cols);
404 if (!buffer)
405 return NULL;
406 ui_help_menu_render(buffer, size, &menu);
407 size_t length = frame_buffer_get_length(buffer);
408 char *result = SAFE_MALLOC(length + 1, char *);
409 memcpy(result, frame_buffer_get_content(buffer), length);
410 result[length] = '\0';
411 frame_buffer_destroy(buffer);
412 return result;
413}
#define SET_ERRNO(code,...)
@ LOG_COLOR_WARN
Definition color.h:10
void frame_buffer_destroy(frame_buffer_t *buf)
Destroy a frame buffer.
size_t frame_buffer_get_length(const frame_buffer_t *buf)
Get the current content length of the frame buffer.
const char * frame_buffer_get_content(const frame_buffer_t *buf)
Get a pointer to the buffer content.
frame_buffer_t * frame_buffer_create(int rows, int cols)
Create a new frame buffer.
struct frame_buffer frame_buffer_t
Opaque frame buffer handle.
#define SAFE_MALLOC(size, cast)
@ ERROR_INVALID_PARAM
#define GET_OPTION(field)
Definition options.h:1339
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
terminal_size_t ui_help_menu_measure(const ui_help_menu_t *m)
Definition help_menu.c:86
bool ui_help_menu_render(frame_buffer_t *out, terminal_size_t size, const ui_help_menu_t *m)
Definition help_menu.c:103
char * ui_session_help_render(terminal_size_t size, bool has_media, bool browser, terminal_size_t *minimum)
#define TUI_SESSION_HELP_FOOTER_BUFFER_SIZE
Definition session_help.c:6
Definition help_menu.h:7
ui help entry keeps the values that move through the subsystem: keys, description....
Definition help_menu.h:19
@ UI_SCREEN_PROMPT
@ UI_SCREEN_ERRNO
@ UI_SCREEN_STATS
@ UI_SCREEN_UPDATE
@ UI_SCREEN_SYNC
@ UI_SCREEN_MDNS
@ UI_SCREEN_ERROR

References colored_string(), ERROR_INVALID_PARAM, frame_buffer_create(), frame_buffer_destroy(), frame_buffer_get_content(), frame_buffer_get_length(), GET_OPTION, LOG_COLOR_WARN, SAFE_MALLOC, SET_ERRNO, TUI_SESSION_HELP_FOOTER_BUFFER_SIZE, ui_help_menu_measure(), ui_help_menu_render(), UI_SCREEN_ERRNO, UI_SCREEN_ERROR, UI_SCREEN_MDNS, UI_SCREEN_PROMPT, UI_SCREEN_STATS, UI_SCREEN_SYNC, UI_SCREEN_UPDATE, and ui_session_help_render().

◆ ui_session_help_free()

void ui_session_help_free ( char * text)

Release rendered help with the same allocator that created it.

Definition at line 33 of file session_help.c.

33{ SAFE_FREE(text); }
#define SAFE_FREE(ptr)

References SAFE_FREE.

Referenced by ui_session_tick().

◆ ui_session_help_render()

char * ui_session_help_render ( terminal_size_t size,
bool has_media,
bool browser,
terminal_size_t * minimum )

Returns owned ANSI text, released with SAFE_FREE.

Definition at line 130 of file session_help.c.

131 {
132 if (!minimum) {
133 SET_ERRNO(ERROR_INVALID_PARAM, "Help minimum geometry output is required");
134 return NULL;
135 }
136 const char *navigation[] = {
137 "Navigation & Control:",
138 "─────────────────────",
139 "? Toggle this help screen TUI",
140 "q / Esc Quit ascii-chat (Shift+Key to panic exit)",
141 browser ? NULL : "v Open from clipboard",
142 browser ? NULL : "Paste Queue dropped/pasted media",
143 browser ? NULL : "< / > Previous/next media (restart)",
144 has_media ? "Space Play/Pause (files only)" : NULL,
145 has_media ? "[ Toggle Media Playback" : NULL,
146 has_media ? (terminal_should_use_utf8(GET_OPTION(force_utf8))
147 ? "← / → Seek backward/forward 30s"
148 : "Left / Right Seek backward/forward 30s")
149 : NULL,
150 "m Mute/Unmute audio",
152 ? "↑ / ↓ Volume up/down (10%)"
153 : "Up / Down Volume up/down (10%)",
154 "c Cycle color mode",
155 "f Cycle color filter",
156 "x Flip webcam horizontally",
157 "y Flip webcam vertically",
158 "w Toggle Face Follow",
159 "Shift-s Toggle stabilization",
160 "r Cycle render mode",
161 "Shift-r Cycle text renderer",
162 "- FPS counter",
163#if defined(ASCIICHAT_DIAGNOSTIC_UI)
164 browser ? NULL : "` Error stacks diagnostic TUI",
165#endif
166 browser ? NULL : "o TUI to open media from path or url",
167 "] Live log viewer/searcher TUI",
168 "F12 Version update checker TUI",
169 browser ? NULL : "= Running app statistics TUI",
170#ifndef NDEBUG
171 browser ? NULL : "0 C code sync primitives TUI",
172#endif
173 };
175 [SESSION_HELP_SETTING_BUFFER_SIZE] = {"Current Settings:", ""};
177 format_volume_bar(GET_OPTION(speakers_volume), volume_bar,
178 sizeof(volume_bar));
179 snprintf(settings[2], sizeof(settings[2]), "Audio : %s",
180 status_indicator(GET_OPTION(audio_enabled)));
181 snprintf(settings[3], sizeof(settings[3]), "Volume : %s", volume_bar);
182 snprintf(settings[4], sizeof(settings[4]), "Color : %s",
184 snprintf(settings[5], sizeof(settings[5]), "Filter : %s",
185 color_filter_to_string(GET_OPTION(color_filter)));
186 snprintf(settings[6], sizeof(settings[6]), "Render : %s",
188 snprintf(settings[7], sizeof(settings[7]), "Renderer: %s",
189 renderer_to_string(GET_OPTION(renderer)));
190 snprintf(settings[8], sizeof(settings[8]), "Flip : rows=%s cols=%s",
191 status_indicator(GET_OPTION(flip_y)),
192 status_indicator(GET_OPTION(flip_x)));
193 snprintf(settings[9], sizeof(settings[9]), "Face Follow : %s",
194 status_indicator(GET_OPTION(face_follow)));
195 snprintf(settings[10], sizeof(settings[10]), "Stabilize: %s",
196 status_indicator(GET_OPTION(stabilize)));
197 int settings_count = 11;
198 settings[settings_count++][0] = '\0';
199 snprintf(settings[settings_count++], sizeof(settings[0]),
200 "Animations (number key toggle):");
201 snprintf(settings[settings_count++], sizeof(settings[0]),
202 "(1) Matrix \"Digital Rain\" : %s",
203 status_indicator(GET_OPTION(matrix_rain)));
204 snprintf(settings[settings_count++], sizeof(settings[0]),
205 "(2) Audio Waveform : %s", status_indicator(GET_OPTION(waveform)));
206 snprintf(settings[settings_count++], sizeof(settings[0]),
207 "(3) Audio Frequencies (FFT) : %s",
208 status_indicator(GET_OPTION(fft)));
209 snprintf(settings[settings_count++], sizeof(settings[0]),
210 "(z) Zalgo intensity : %d", GET_OPTION(zalgo));
211 snprintf(settings[settings_count++], sizeof(settings[0]),
212 "(-) FPS Counter : %s", status_indicator(GET_OPTION(fps_counter)));
213 bool server = !browser && (GET_OPTION(detected_mode) == MODE_SERVER ||
214 GET_OPTION(detected_mode) == MODE_MCP_SERVER);
215 bool discovery =
216 !browser && GET_OPTION(detected_mode) == MODE_DISCOVERY_SERVICE;
218 char key_storage[TUI_SESSION_HELP_KEY_STORAGE_COUNT]
220 size_t count = 0;
221 for (size_t i = 0; i < sizeof(navigation) / sizeof(navigation[0]); ++i) {
222 const char *line = navigation[i];
223 if (!line || i == 1)
224 continue;
225 if (line[0] == '?' || line[0] == ']' || line[0] == '=' || line[0] == '0' ||
226 line[0] == '`' || line[0] == 'o' || !strncmp(line, "F12", 3))
227 continue;
228 if ((server || discovery) && i > 1 && line[0] != '?' &&
229 strncmp(line, "Esc", 3) && line[0] != ']' && line[0] != '=' &&
230 line[0] != '0' && line[0] != '`' && strncmp(line, "F12", 3))
231 continue;
232 const char *end = strstr(line, " ");
233 if (end) {
234 size_t length = (size_t)(end - line);
235 if (length >= sizeof(key_storage[0]))
236 length = sizeof(key_storage[0]) - 1;
237 memcpy(key_storage[count], line, length);
238 key_storage[count][length] = '\0';
239 while (*end == ' ')
240 ++end;
241 entries[count] =
242 (ui_help_entry_t){.keys = key_storage[count], .description = end};
243 } else
244 entries[count] = (ui_help_entry_t){.description = line};
245 ++count;
246 }
247 count += tui_shortcut_help(entries + count, 40 - count, server || discovery,
248 browser);
249 if (server || discovery) {
250 settings_count = 4;
251 snprintf(settings[0], sizeof(settings[0]), "%s",
252 discovery ? "Discovery service:" : "Server:");
253 snprintf(settings[1], sizeof(settings[1]), "Port : %d", GET_OPTION(port));
254 snprintf(settings[2], sizeof(settings[2]), "Status screen : %s",
255 status_indicator(GET_OPTION(status_screen)));
256 snprintf(settings[3], sizeof(settings[3]), "Log level : %d",
257 GET_OPTION(log_level));
258 }
259 const char *settings_text[TUI_SESSION_HELP_SETTINGS_COUNT];
260 for (int i = 0; i < settings_count; ++i)
261 settings_text[i] = settings[i];
263 snprintf(footer, sizeof(footer), "Press %s to close",
265 ui_help_menu_t menu = {
266 .title = discovery ? "ascii-chat Discovery Service Keyboard Shortcuts"
267 : server ? "ascii-chat Server Keyboard Shortcuts"
268 : "ascii-chat Keyboard Shortcuts",
269 .entries = entries,
270 .count = count,
271 .settings = settings_text,
272 .settings_count = (size_t)settings_count,
273 .footer = footer,
274 // Browser sessions draw a four-row animated logo above the popup.
275 .top_margin = browser ? 6 : 0};
276 *minimum = ui_help_menu_measure(&menu);
277 frame_buffer_t *output = frame_buffer_create(size.rows, size.cols);
278 if (!output)
279 return NULL;
280 ui_help_menu_render(output, size, &menu);
281 size_t length = frame_buffer_get_length(output);
282 char *result = SAFE_MALLOC(length + 1, char *);
283 memcpy(result, frame_buffer_get_content(output), length);
284 result[length] = '\0';
285 frame_buffer_destroy(output);
286 return result;
287}
int color_mode
Definition fft.c:26
terminal_render_mode_t render_mode
Definition fft.c:27
@ MODE_MCP_SERVER
Model Context Protocol rendering server.
Definition options.h:922
@ MODE_DISCOVERY_SERVICE
Discovery server mode - session management and WebRTC signaling.
Definition options.h:920
@ MODE_SERVER
Server mode - network server options.
Definition options.h:917
const char * color_mode_to_string(terminal_color_mode_t mode)
Convert color mode enum to string.
const char * render_mode_to_string(terminal_render_mode_t mode)
if(!queries||!out||index >=DATABASE_QUERY_COUNT) return false
#define TUI_SESSION_HELP_KEY_STORAGE_COUNT
Definition session_help.c:5
#define SESSION_HELP_ENTRY_CAPACITY
#define TUI_SESSION_HELP_VOLUME_BAR_BUFFER_SIZE
Definition session_help.c:4
#define SESSION_HELP_KEY_BUFFER_SIZE
#define SESSION_HELP_SETTING_BUFFER_SIZE
Definition session_help.c:9
#define TUI_SESSION_HELP_SETTINGS_COUNT
Definition session_help.c:3
size_t tui_shortcut_help(ui_help_entry_t *entries, size_t capacity, bool server, bool browser)
Definition shortcuts.c:70
bool terminal_should_use_utf8(terminal_utf8_setting_t user_setting)

References color_mode, color_mode_to_string(), colored_string(), ERROR_INVALID_PARAM, frame_buffer_create(), frame_buffer_destroy(), frame_buffer_get_content(), frame_buffer_get_length(), GET_OPTION, LOG_COLOR_WARN, MODE_DISCOVERY_SERVICE, MODE_MCP_SERVER, MODE_SERVER, render_mode, render_mode_to_string(), SAFE_MALLOC, SESSION_HELP_ENTRY_CAPACITY, SESSION_HELP_KEY_BUFFER_SIZE, SESSION_HELP_SETTING_BUFFER_SIZE, SET_ERRNO, terminal_should_use_utf8(), TUI_SESSION_HELP_FOOTER_BUFFER_SIZE, TUI_SESSION_HELP_KEY_STORAGE_COUNT, TUI_SESSION_HELP_SETTINGS_COUNT, TUI_SESSION_HELP_VOLUME_BAR_BUFFER_SIZE, tui_shortcut_help(), ui_help_menu_measure(), and ui_help_menu_render().

Referenced by ui_session_context_help_render(), and ui_session_tick().