dte test coverage


Directory: ./
File: src/terminal/key.h
Date: 2025-02-14 16:55:22
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 #ifndef TERMINAL_KEY_H
2 #define TERMINAL_KEY_H
3
4 #include <stddef.h>
5 #include <stdint.h>
6 #include "util/ascii.h"
7 #include "util/macros.h"
8
9 enum {
10 // Maximum length of string produced by keycode_to_string()
11 KEYCODE_STR_MAX = 32 // sizeof("QUERY REPLY; 0x12345678")
12 };
13
14 // NOLINTNEXTLINE(readability-enum-initial-value,cert-int09-c)
15 enum {
16 KEY_NONE = 0,
17 KEY_TAB = '\t',
18 KEY_ENTER = '\n',
19 KEY_SPACE = ' ',
20
21 // This is the maximum Unicode codepoint allowed by RFC 3629.
22 // When stored in a 32-bit integer, it only requires the first
23 // 21 low-order bits, leaving 11 high-order bits available to
24 // be used as bit flags.
25 KEY_UNICODE_MAX = 0x10FFFF, // UNICODE_MAX_VALID_CODEPOINT
26 KEY_MASK = 0x1FFFFF, // (1 << 21) - 1
27
28 // In addition to the 11 unused, high-order bits, there are also
29 // 983,042 unused values in the range from KEY_UNICODE_MAX + 1 to
30 // KEY_MASK, which can be used to represent special keys.
31 KEY_SPECIAL_MIN = KEY_UNICODE_MAX + 1,
32
33 // Note: these must be kept in sync with the array of names in key.c
34 KEY_ESCAPE = KEY_SPECIAL_MIN,
35 KEY_BACKSPACE,
36 KEY_INSERT,
37 KEY_DELETE,
38 KEY_HOME,
39 KEY_END,
40 KEY_PAGE_UP,
41 KEY_PAGE_DOWN,
42 KEY_UP,
43 KEY_DOWN,
44 KEY_RIGHT,
45 KEY_LEFT,
46 KEY_BEGIN, // Keypad '5'
47 KEY_SCROLL_LOCK,
48 KEY_PRINT_SCREEN,
49 KEY_PAUSE,
50 KEY_MENU,
51 KEY_F1,
52 KEY_F2,
53 KEY_F3,
54 KEY_F4,
55 KEY_F5,
56 KEY_F6,
57 KEY_F7,
58 KEY_F8,
59 KEY_F9,
60 KEY_F10,
61 KEY_F11,
62 KEY_F12,
63 KEY_F13,
64 KEY_F14,
65 KEY_F15,
66 KEY_F16,
67 KEY_F17,
68 KEY_F18,
69 KEY_F19,
70 KEY_F20,
71
72 KEY_SPECIAL_MAX = KEY_F20,
73 NR_SPECIAL_KEYS = KEY_SPECIAL_MAX - KEY_SPECIAL_MIN + 1,
74
75 // In-band signalling for non-key events
76 KEYCODE_DETECTED_PASTE = KEY_SPECIAL_MAX + 1,
77 KEYCODE_BRACKETED_PASTE,
78 KEY_IGNORE,
79
80 // Modifier bit flags (as described above)
81 // See also: decode_modifiers()
82 KEYCODE_MODIFIER_OFFSET = 21,
83 MOD_SHIFT = 1 << KEYCODE_MODIFIER_OFFSET,
84 MOD_META = 2 << KEYCODE_MODIFIER_OFFSET,
85 MOD_CTRL = 4 << KEYCODE_MODIFIER_OFFSET,
86 MOD_SUPER = 8 << KEYCODE_MODIFIER_OFFSET,
87 MOD_HYPER = 16 << KEYCODE_MODIFIER_OFFSET,
88 MOD_MASK = MOD_SHIFT | MOD_META | MOD_CTRL | MOD_SUPER | MOD_HYPER,
89
90 // If this bit is set, all other bits correspond to TermFeatureFlags.
91 // This is used by the functions in query.c to communicate replies to
92 // term_read_input(), although such values are handled entirely within
93 // that function and are never present in KeyCode values it returns.
94 KEYCODE_QUERY_REPLY_BIT = 1u << 30,
95 };
96
97 typedef uint32_t KeyCode;
98
99 536 static inline KeyCode keycode_get_key(KeyCode k)
100 {
101 536 return k & KEY_MASK;
102 }
103
104 static inline KeyCode keycode_get_modifiers(KeyCode k)
105 {
106 return k & MOD_MASK;
107 }
108
109 KeyCode parse_key_string(const char *str) NONNULL_ARGS WARN_UNUSED_RESULT;
110 size_t keycode_to_string(KeyCode key, char *buf) NONNULL_ARGS;
111
112 #endif
113