ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
keyboard_help.c
Go to the documentation of this file.
1#include "session/display.h"
2#include <ascii-chat/common.h>
3#include <ascii-chat/otel.h>
7#include <options/options.h>
8#include <options/runtime.h>
9#include <stdatomic.h>
10#include <string.h>
11
12static atomic_int g_help_parent = -1;
13static atomic_int g_help_previous = -1;
14static char *g_help_text;
15static terminal_size_t g_help_size;
16static terminal_size_t g_help_minimum;
17static int g_help_cached_parent = -1;
18static uint64_t g_help_revision;
19
20static char *keyboard_help_text(terminal_size_t size,
21 terminal_size_t *minimum) {
22 int parent = keyboard_help_parent_screen();
23 uint64_t revision = options_revision();
24 if (!g_help_text || g_help_size.cols != size.cols ||
25 g_help_size.rows != size.rows || g_help_cached_parent != parent ||
26 g_help_revision != revision) {
27 terminal_size_t rendered_minimum;
28 char *text = ui_session_context_help_render(size, (ui_screen_t)parent,
29 &rendered_minimum);
30 if (!text)
31 return NULL;
32 SAFE_FREE(g_help_text);
33 g_help_text = text;
34 g_help_size = size;
35 g_help_minimum = rendered_minimum;
36 g_help_cached_parent = parent;
37 g_help_revision = revision;
38 }
39 if (minimum)
40 *minimum = g_help_minimum;
41 return g_help_text;
42}
43
44static void render_help_snapshot(terminal_size_t size, const void *data) {
45 int fd = *(const int *)data;
46 char *text = keyboard_help_text(size, NULL);
47 if (text)
48 ui_controller_write(fd, text, strlen(text));
49}
51 return atomic_load(&g_help_previous);
52}
53int keyboard_help_parent_screen(void) { return atomic_load(&g_help_parent); }
54
55const char *keyboard_help_screen_name(int parent) {
56 switch (parent) {
57 case UI_SCREEN_STATS:
58 return "stats_help";
59 case UI_SCREEN_SYNC:
60 return "sync_help";
61 case UI_SCREEN_ERRNO:
62 return "errno_help";
64 return "media_input_help";
65 case UI_SCREEN_MDNS:
66 return "mdns_help";
68 return "update_help";
69 case UI_SCREEN_ERROR:
70 return "error_help";
71 default:
72 return "help";
73 }
74}
75
80 ascii_otel_ui_usage(keyboard_help_screen_name(parent), "shortcut", 0);
82 // Keep the underlying worker active throughout dismissal. An intermediate
83 // empty selection could make it retire its screen after we restore it.
85 return;
86 }
87 if (parent == UI_SCREEN_ERROR)
88 ascii_otel_ui_usage("error", "help_viewed", 0);
89 atomic_store(&g_help_previous, ui_controller_interactive_screen());
90 atomic_store(&g_help_parent, ui_controller_current_screen());
91 terminal_size_t minimum;
92 char *text = keyboard_help_text(ui_controller_size(), &minimum);
93 if (!text)
94 return;
95 if (!GET_OPTION(snapshot_mode))
96 (void)ui_controller_submit(UI_SCREEN_HELP, fd, minimum,
97 render_help_snapshot, &fd, sizeof(fd));
98}
99
101 if (ctx)
102 keyboard_help_toggle_terminal(STDOUT_FILENO);
103}
104
#define SAFE_FREE(ptr)
unsigned long long uint64_t
#define GET_OPTION(field)
Definition options.h:1339
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)
⚙️ Common definitions, error codes, macros, and types shared throughout the application
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:506
uint64_t options_revision(void)
Definition rcu.c:945
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