ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
shortcuts.c
Go to the documentation of this file.
1
2/* Existing buffer budgets in bytes, including NUL for text storage. */
3#define SHORTCUT_MAX_KEYS 3
4
7typedef struct {
8 keyboard_key_t keys[SHORTCUT_MAX_KEYS];
10 const char *label, *description;
17} binding_t;
18static const binding_t bindings[] = {
19 {{KEY_QUESTION},
21 "?",
22 "Toggle this help screen TUI",
23 false,
24 false},
25 {{']'},
27 "]",
28 "Live log viewer/searcher TUI",
29 false,
30 false},
31 {{'='}, TUI_SHORTCUT_STATS, "=", "Running app statistics TUI", true, false},
32#ifndef NDEBUG
33 {{KEY_0},
35 "0",
36 "C code sync primitives TUI",
37 true,
38 false},
39#endif
40#if defined(ASCIICHAT_DIAGNOSTIC_UI)
41 {{KEY_BACKTICK},
43 "`",
44 "Error stacks diagnostic TUI",
45 true,
46 false},
47#endif
48 {{KEY_F12},
50 "F12",
51 "Version update checker TUI",
52 true,
53 false},
54 {{'o', 'O', 15},
56 "o / Ctrl-O",
57 "TUI to open media from path or URL",
58 true,
59 true},
60};
62 if (key == KEY_NONE)
63 return TUI_SHORTCUT_NONE;
64 for (size_t i = 0; i < sizeof(bindings) / sizeof(*bindings); ++i)
65 for (size_t alias = 0; alias < 3; ++alias)
66 if (bindings[i].keys[alias] == key)
67 return bindings[i].action;
68 return TUI_SHORTCUT_NONE;
69}
70size_t tui_shortcut_help(ui_help_entry_t *entries, size_t capacity, bool server,
71 bool browser) {
72 if (!entries || !capacity) {
73 SET_ERRNO(ERROR_INVALID_PARAM, "Help binding output is required");
74 return 0;
75 }
76 size_t count = 0;
77 for (size_t i = 0; i < sizeof(bindings) / sizeof(*bindings); ++i) {
78 const binding_t *b = &bindings[i];
79 if ((server && b->media) || (browser && b->native))
80 continue;
81 if (count >= capacity) {
82 SET_ERRNO(ERROR_BUFFER_OVERFLOW, "Help binding output is too small");
83 return 0;
84 }
85 entries[count++] =
86 (ui_help_entry_t){.keys = b->label, .description = b->description};
87 }
88 return count;
89}
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
@ ERROR_INVALID_PARAM
@ ERROR_BUFFER_OVERFLOW
tui_shortcut_t tui_shortcut_action(keyboard_key_t key)
Definition shortcuts.c:61
#define SHORTCUT_MAX_KEYS
Definition shortcuts.c:3
size_t tui_shortcut_help(ui_help_entry_t *entries, size_t capacity, bool server, bool browser)
Definition shortcuts.c:70
tui_shortcut_t
Definition shortcuts.h:8
@ TUI_SHORTCUT_LOGS
Definition shortcuts.h:11
@ TUI_SHORTCUT_MEDIA
Definition shortcuts.h:16
@ TUI_SHORTCUT_UPDATE
Definition shortcuts.h:15
@ TUI_SHORTCUT_SYNC
Definition shortcuts.h:13
@ TUI_SHORTCUT_HELP
Definition shortcuts.h:10
@ TUI_SHORTCUT_STATS
Definition shortcuts.h:12
@ TUI_SHORTCUT_NONE
Definition shortcuts.h:9
@ TUI_SHORTCUT_ERRORS
Definition shortcuts.h:14
const char * label
Definition shortcuts.c:10
bool native
Definition shortcuts.c:11
keyboard_key_t keys[3]
Definition shortcuts.c:8
tui_shortcut_t action
Definition shortcuts.c:9
bool media
Definition shortcuts.c:11
const char * description
Definition shortcuts.c:10
Definition help_menu.h:7