ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
keyboard_help.c
Go to the documentation of this file.
1#include <stdatomic.h>
2#include <ascii-chat/otel.h>
6#include <ascii-chat/common.h>
8#include "session/display.h"
9#include <string.h>
10
11static atomic_int g_help_parent = -1;
12static atomic_int g_help_previous = -1;
14 return atomic_load(&g_help_previous);
15}
17 return atomic_load(&g_help_parent);
18}
19
20const char *keyboard_help_screen_name(int parent) {
21 switch (parent) {
22 case UI_SCREEN_STATS:
23 return "stats_help";
24 case UI_SCREEN_SYNC:
25 return "sync_help";
26 case UI_SCREEN_ERRNO:
27 return "errno_help";
29 return "media_input_help";
30 case UI_SCREEN_MDNS:
31 return "mdns_help";
33 return "update_help";
34 case UI_SCREEN_ERROR:
35 return "error_help";
36 default:
37 return "help";
38 }
39}
40
41static void render_help_snapshot(terminal_size_t size, const void *data) {
42 int fd = *(const int *)data;
43 terminal_size_t minimum;
45 if (text) {
46 ui_controller_write(fd, text, strlen(text));
47 SAFE_FREE(text);
48 }
49}
50
52 int parent =
54 ascii_otel_ui_usage(keyboard_help_screen_name(parent), "shortcut", 0);
56 // Keep the underlying worker active throughout dismissal. An intermediate
57 // empty selection could make it retire its screen after we restore it.
59 return;
60 }
61 if (parent == UI_SCREEN_ERROR)
62 ascii_otel_ui_usage("error", "help_viewed", 0);
63 atomic_store(&g_help_previous, ui_controller_interactive_screen());
64 atomic_store(&g_help_parent, ui_controller_current_screen());
65 terminal_size_t minimum;
66 char *text =
68 if (!text)
69 return;
70 if (!GET_OPTION(snapshot_mode))
71 (void)ui_controller_submit(UI_SCREEN_HELP, fd, minimum, render_help_snapshot, &fd, sizeof(fd));
72 SAFE_FREE(text);
73}
74
76 if (ctx)
77 keyboard_help_toggle_terminal(STDOUT_FILENO);
78}
79
⚙️ Common definitions, error codes, macros, and types shared throughout the application
#define SAFE_FREE(ptr)
Definition common.h:377
#define GET_OPTION(field)
Safely get a specific option field (lock-free read).
Definition options.h:1336
void keyboard_help_toggle_terminal(int fd)
void keyboard_help_toggle(session_display_ctx_t *ctx)
Toggle keyboard help on/off.
bool keyboard_help_is_active(session_display_ctx_t *ctx)
Check if keyboard help is currently active.
struct session_display_ctx session_display_ctx_t
session display config is intentionally a small, concrete record. Fields such as snapshot_mode,...
int keyboard_help_parent_screen(void)
void keyboard_help_render(session_display_ctx_t *ctx)
Render keyboard help TUI overlay.
const char * keyboard_help_screen_name(int parent)
int keyboard_help_previous_interactive(void)
🆘 Interactive keyboard help overlay for session keyboard shortcuts
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
void ascii_otel_ui_usage(const char *screen, const char *event, uint64_t duration_ns)
Definition otel.c:434
char * ui_session_context_help_render(terminal_size_t size, ui_screen_t screen, terminal_size_t *minimum)
🖥️ Unified terminal display abstraction for session-based rendering
🔤 String Manipulation and Shell Escaping Utilities
void ui_controller_dismiss(ui_screen_t screen, int previous)
asciichat_error_t ui_controller_submit(ui_screen_t screen, int fd, terminal_size_t minimum, ui_render_fn render, const void *snapshot, size_t bytes)
void ui_controller_redraw(void)
int ui_controller_current_screen(void)
terminal_size_t ui_controller_size(void)
int ui_controller_interactive_screen(void)
asciichat_error_t ui_controller_write(int fd, const char *data, size_t len)
ui_screen_t
@ UI_SCREEN_PROMPT
@ UI_SCREEN_ERRNO
@ UI_SCREEN_STATS
@ UI_SCREEN_UPDATE
@ UI_SCREEN_SYNC
@ UI_SCREEN_MDNS
@ UI_SCREEN_HELP
@ UI_SCREEN_ERROR