diff options
author | Michael Brown <mcb30@ipxe.org> | 2023-07-04 14:31:07 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2023-07-04 14:33:43 +0100 |
commit | 3ef4f7e2ef4a22ea1e2eccc72957d7bf3fe2f945 (patch) | |
tree | 9ae790d320e9410b4dfa58a57cf3b51e418b0de6 /src/include/ipxe/keys.h | |
parent | cc07ed7c7ede8dfc79643ccabb32285c74d6bff5 (diff) | |
download | ipxe-3ef4f7e2ef4a22ea1e2eccc72957d7bf3fe2f945.tar.gz |
[console] Avoid overlap between special keys and Unicode characters
The special key range (from KEY_MIN upwards) currently overlaps with
the valid range for Unicode characters, and therefore prohibits the
use of Unicode key values outside the ASCII range.
Create space for Unicode key values by moving the special keys to the
range immediately above the maximum valid Unicode character. This
allows the existing encoding of special keys as an efficiently packed
representation of the equivalent ANSI escape sequence to be maintained
almost as-is.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/keys.h')
-rw-r--r-- | src/include/ipxe/keys.h | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/include/ipxe/keys.h b/src/include/ipxe/keys.h index d15267a1f..23356913d 100644 --- a/src/include/ipxe/keys.h +++ b/src/include/ipxe/keys.h @@ -49,19 +49,54 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ESC 0x1b /* - * Special keys outside the normal ASCII range - * + * Special keys outside the normal Unicode range * * The names are chosen to match those used by curses. The values are * chosen to facilitate easy conversion from a received ANSI escape * sequence to a KEY_XXX constant. */ -#define KEY_ANSI( n, terminator ) ( 0x100 * ( (n) + 1 ) + (terminator) ) -#define KEY_ANSI_N( key ) ( ( (key) / 0x100 ) - 1 ) +/** + * Minimum value for special keypresses + * + * This value is chosen to lie above the maximum Unicode code point + * value 0x10ffff. + */ +#define KEY_MIN 0x110000 + +/** + * Construct relative key value for special key + * + * @v key Key value + * @ret rkey Relative key value + */ +#define KEY_REL( key ) ( (key) - KEY_MIN ) + +/** + * Construct ANSI escape sequence key value + * + * @v n ANSI escape sequence numeric portion, or 0 for none + * @v terminator ANSI escape sequence terminating character + * @ret key Key value + */ +#define KEY_ANSI( n, terminator ) ( KEY_MIN + ( (n) << 8 ) + (terminator) ) + +/** + * Extract ANSI escape sequence numeric portion + * + * @v key Key value (or relative key value) + * @ret n ANSI escape sequence numeric portion, or 0 for none + */ +#define KEY_ANSI_N( key ) ( ( (key) >> 8 ) & 0xff ) + +/** + * Extract ANSI escape sequence terminating character + * + * @v key Key value (or relative key value) + * @ret terminator ANSI escape sequence terminating character + */ #define KEY_ANSI_TERMINATOR( key ) ( (key) & 0xff ) -#define KEY_MIN 0x101 #define KEY_UP KEY_ANSI ( 0, 'A' ) /**< Up arrow */ #define KEY_DOWN KEY_ANSI ( 0, 'B' ) /**< Down arrow */ #define KEY_RIGHT KEY_ANSI ( 0, 'C' ) /**< Right arrow */ |