ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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
17static const binding_t bindings[] = {
18 {{KEY_QUESTION}, TUI_SHORTCUT_HELP, "?", "Toggle this help screen TUI", false, false},
19 {{']'}, TUI_SHORTCUT_LOGS, "]", "Live log viewer/searcher TUI", false, false},
20 {{'='}, TUI_SHORTCUT_STATS, "=", "Running app statistics TUI", true, false},
21#ifndef NDEBUG
22 {{KEY_0}, TUI_SHORTCUT_SYNC, "0", "C code sync primitives TUI", true, false},
23#endif
24#if defined(ASCIICHAT_DIAGNOSTIC_UI)
25 {{KEY_BACKTICK}, TUI_SHORTCUT_ERRORS, "`", "Error stacks diagnostic TUI", true, false},
26#endif
27 {{KEY_F12}, TUI_SHORTCUT_UPDATE, "F12", "Version update checker TUI", true, false},
28 {{'o', 'O', 15}, TUI_SHORTCUT_MEDIA, "o / Ctrl-O", "TUI to open media from path or URL", true, true},
29};
31 if (key == KEY_NONE)
32 return TUI_SHORTCUT_NONE;
33 for (size_t i = 0; i < sizeof(bindings) / sizeof(*bindings); ++i)
34 for (size_t alias = 0; alias < 3; ++alias)
35 if (bindings[i].keys[alias] == key)
36 return bindings[i].action;
37 return TUI_SHORTCUT_NONE;
38}
39size_t tui_shortcut_help(ui_help_entry_t *entries, size_t capacity, bool server, bool browser) {
40 if (!entries || !capacity) {
41 SET_ERRNO(ERROR_INVALID_PARAM, "Help binding output is required");
42 return 0;
43 }
44 size_t count = 0;
45 for (size_t i = 0; i < sizeof(bindings) / sizeof(*bindings); ++i) {
46 const binding_t *b = &bindings[i];
47 if ((server && b->media) || (browser && b->native))
48 continue;
49 if (count >= capacity) {
50 SET_ERRNO(ERROR_BUFFER_OVERFLOW, "Help binding output is too small");
51 return 0;
52 }
53 entries[count++] = (ui_help_entry_t){.keys = b->label, .description = b->description};
54 }
55 return count;
56}
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
@ ERROR_INVALID_PARAM
@ ERROR_BUFFER_OVERFLOW
keyboard_key_t
Options for interactive line editing.
Definition keyboard.h:53
@ KEY_BACKTICK
'`' key - print lock state (debug builds)
Definition keyboard.h:84
@ KEY_0
'0' key - toggle sync debug screen
Definition keyboard.h:75
@ KEY_F12
Open the version update checker TUI.
Definition keyboard.h:69
@ KEY_NONE
No key pressed or no input available.
Definition keyboard.h:54
@ KEY_QUESTION
'?' key - show help screen
Definition keyboard.h:83
tui_shortcut_t tui_shortcut_action(keyboard_key_t key)
Definition shortcuts.c:30
#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:39
tui_shortcut_t
Definition shortcuts.h:4
@ TUI_SHORTCUT_LOGS
Definition shortcuts.h:7
@ TUI_SHORTCUT_MEDIA
Definition shortcuts.h:12
@ TUI_SHORTCUT_UPDATE
Definition shortcuts.h:11
@ TUI_SHORTCUT_SYNC
Definition shortcuts.h:9
@ TUI_SHORTCUT_HELP
Definition shortcuts.h:6
@ TUI_SHORTCUT_STATS
Definition shortcuts.h:8
@ TUI_SHORTCUT_NONE
Definition shortcuts.h:5
@ TUI_SHORTCUT_ERRORS
Definition shortcuts.h:10
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:3