From 5d536ad95897e15cc454330aa7bd35ae94df8ac7 Mon Sep 17 00:00:00 2001 From: mateolafalce Date: Mon, 25 Dec 2023 21:27:17 +0800 Subject: [PATCH] 1.2.1 --- Cargo.toml | 9 ++++-- README.md | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/keys.rs | 61 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 30 +++++++++++++----- 4 files changed, 178 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d543d34..6d0e1d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "k_board" -version = "1.2.0" +version = "1.2.1" edition = "2021" license = "GPL-3.0" -authors = ["Mateo Lafalce", "mateolafalce@protonmail.com"] +authors = ["Mateo Lafalce "] description = "A keyboard event handler that allows dynamic development" keywords = ["keyboard", "terminal", "tui", "tty", "termios"] repository = "https://github.com/mateolafalce/k_board" @@ -20,4 +20,7 @@ lower_letter = [] upper_letter = [] f = [] ctrl_lower_letter = [] -alt_lower_letter = [] \ No newline at end of file +alt_lower_letter = [] +alt_upper_letter = [] +alt_gr_letter = [] +full = [] \ No newline at end of file diff --git a/README.md b/README.md index e6c0382..eee4f01 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ pub enum Keys { F(u8), Ctrl(char), Alt(char), + AltGr(char), Null, } ``` @@ -106,7 +107,10 @@ The library has different features depending on the developer's needs. - upper_letter - f - ctrl_lower_letter -- alt_lower_letter +- alt_lower_letter +- alt_upper_letter +- alt_gr_lower_letter +- full
no-feature(default) @@ -353,4 +357,87 @@ pub const ALT_LOWER_LETTER: [([u8; BYTES], Keys); 27] = [ ([0x1b, 0x7a, 0x00], Keys::Alt('z')), ]; ``` +
+ + +
+alt_upper_letter + +```rust +pub const ALT_UPPER_LETTER: [([u8; BYTES], Keys); 27] = [ + ([0x1b, 0x41, 0x00], Keys::Alt('A')), + ([0x1b, 0x42, 0x00], Keys::Alt('B')), + ([0x1b, 0x43, 0x00], Keys::Alt('C')), + ([0x1b, 0x44, 0x00], Keys::Alt('D')), + ([0x1b, 0x45, 0x00], Keys::Alt('E')), + ([0x1b, 0x46, 0x00], Keys::Alt('F')), + ([0x1b, 0x47, 0x00], Keys::Alt('G')), + ([0x1b, 0x48, 0x00], Keys::Alt('H')), + ([0x1b, 0x49, 0x00], Keys::Alt('I')), + ([0x1b, 0x4A, 0x00], Keys::Alt('J')), + ([0x1b, 0x4B, 0x00], Keys::Alt('K')), + ([0x1b, 0x4C, 0x00], Keys::Alt('L')), + ([0x1b, 0x4D, 0x00], Keys::Alt('M')), + ([0x1b, 0x4E, 0x00], Keys::Alt('N')), + ([0x1b, 0xc3, 0x91], Keys::Alt('Ñ')), + ([0x1b, 0x4f, 0x00], Keys::Alt('O')), + ([0x1b, 0x50, 0x00], Keys::Alt('P')), + ([0x1b, 0x51, 0x00], Keys::Alt('Q')), + ([0x1b, 0x52, 0x00], Keys::Alt('R')), + ([0x1b, 0x53, 0x00], Keys::Alt('S')), + ([0x1b, 0x54, 0x00], Keys::Alt('T')), + ([0x1b, 0x55, 0x00], Keys::Alt('U')), + ([0x1b, 0x56, 0x00], Keys::Alt('V')), + ([0x1b, 0x57, 0x00], Keys::Alt('W')), + ([0x1b, 0x58, 0x00], Keys::Alt('X')), + ([0x1b, 0x59, 0x00], Keys::Alt('Y')), + ([0x1b, 0x5A, 0x00], Keys::Alt('Z')), +]; +``` + +
+alt_gr_letter + +```rust +pub const ALT_GR_LETTER: [([u8; BYTES], Keys); 27] = [ + ([0xc3, 0xa6, 0x00], Keys::AltGr('a')), + ([0xe2, 0x80, 0x9c], Keys::AltGr('b')), + ([0xc2, 0xa2, 0x00], Keys::AltGr('c')), + ([0xc3, 0xb0, 0x00], Keys::AltGr('d')), + ([0xe2, 0x82, 0xac], Keys::AltGr('e')), + ([0xc4, 0x91, 0x00], Keys::AltGr('f')), + ([0xc5, 0x8b, 0x00], Keys::AltGr('g')), + ([0xc4, 0xa7, 0x00], Keys::AltGr('h')), + ([0xe2, 0x86, 0x92], Keys::AltGr('i')), + ([0xcc, 0x89, 0x00], Keys::AltGr('j')), + ([0xc4, 0xb8, 0x00], Keys::AltGr('k')), + ([0xc5, 0x82, 0x00], Keys::AltGr('l')), + ([0xc2, 0xb5, 0x00], Keys::AltGr('m')), + ([0xe2, 0x80, 0x9d], Keys::AltGr('n')), + ([0x7e, 0x00, 0x00], Keys::AltGr('ñ')), + ([0xc3, 0xb8, 0x00], Keys::AltGr('o')), + ([0xc3, 0xbe, 0x00], Keys::AltGr('p')), + ([0x40, 0x00, 0x00], Keys::AltGr('q')), + ([0xc2, 0xb6, 0x00], Keys::AltGr('r')), + ([0xc3, 0x9f, 0x00], Keys::AltGr('s')), + ([0xc5, 0xa7, 0x00], Keys::AltGr('t')), + ([0xe2, 0x86, 0x93], Keys::AltGr('u')), + ([0xe2, 0x80, 0x9e], Keys::AltGr('v')), + ([0xc5, 0xbf, 0x00], Keys::AltGr('w')), + ([0xc2, 0xbb, 0x00], Keys::AltGr('x')), + ([0xe2, 0x86, 0x90], Keys::AltGr('y')), + ([0xc2, 0xab, 0x00], Keys::AltGr('z')), +]; +``` + +
+ + +
+ +
+full + +all features! +
\ No newline at end of file diff --git a/src/keys.rs b/src/keys.rs index edb84a4..b83f5f3 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -18,6 +18,7 @@ pub enum Keys { F(u8), Ctrl(char), Alt(char), + AltGr(char), Null, } @@ -215,3 +216,63 @@ pub const ALT_LOWER_LETTER: [([u8; BYTES], Keys); 27] = [ ([0x1b, 0x79, 0x00], Keys::Alt('y')), ([0x1b, 0x7a, 0x00], Keys::Alt('z')), ]; + +pub const ALT_UPPER_LETTER: [([u8; BYTES], Keys); 27] = [ + ([0x1b, 0x41, 0x00], Keys::Alt('A')), + ([0x1b, 0x42, 0x00], Keys::Alt('B')), + ([0x1b, 0x43, 0x00], Keys::Alt('C')), + ([0x1b, 0x44, 0x00], Keys::Alt('D')), + ([0x1b, 0x45, 0x00], Keys::Alt('E')), + ([0x1b, 0x46, 0x00], Keys::Alt('F')), + ([0x1b, 0x47, 0x00], Keys::Alt('G')), + ([0x1b, 0x48, 0x00], Keys::Alt('H')), + ([0x1b, 0x49, 0x00], Keys::Alt('I')), + ([0x1b, 0x4A, 0x00], Keys::Alt('J')), + ([0x1b, 0x4B, 0x00], Keys::Alt('K')), + ([0x1b, 0x4C, 0x00], Keys::Alt('L')), + ([0x1b, 0x4D, 0x00], Keys::Alt('M')), + ([0x1b, 0x4E, 0x00], Keys::Alt('N')), + ([0x1b, 0xc3, 0x91], Keys::Alt('Ñ')), + ([0x1b, 0x4f, 0x00], Keys::Alt('O')), + ([0x1b, 0x50, 0x00], Keys::Alt('P')), + ([0x1b, 0x51, 0x00], Keys::Alt('Q')), + ([0x1b, 0x52, 0x00], Keys::Alt('R')), + ([0x1b, 0x53, 0x00], Keys::Alt('S')), + ([0x1b, 0x54, 0x00], Keys::Alt('T')), + ([0x1b, 0x55, 0x00], Keys::Alt('U')), + ([0x1b, 0x56, 0x00], Keys::Alt('V')), + ([0x1b, 0x57, 0x00], Keys::Alt('W')), + ([0x1b, 0x58, 0x00], Keys::Alt('X')), + ([0x1b, 0x59, 0x00], Keys::Alt('Y')), + ([0x1b, 0x5A, 0x00], Keys::Alt('Z')), +]; + +pub const ALT_GR_LETTER: [([u8; BYTES], Keys); 27] = [ + ([0xc3, 0xa6, 0x00], Keys::AltGr('a')), + ([0xe2, 0x80, 0x9c], Keys::AltGr('b')), + ([0xc2, 0xa2, 0x00], Keys::AltGr('c')), + ([0xc3, 0xb0, 0x00], Keys::AltGr('d')), + ([0xe2, 0x82, 0xac], Keys::AltGr('e')), + ([0xc4, 0x91, 0x00], Keys::AltGr('f')), + ([0xc5, 0x8b, 0x00], Keys::AltGr('g')), + ([0xc4, 0xa7, 0x00], Keys::AltGr('h')), + ([0xe2, 0x86, 0x92], Keys::AltGr('i')), + ([0xcc, 0x89, 0x00], Keys::AltGr('j')), + ([0xc4, 0xb8, 0x00], Keys::AltGr('k')), + ([0xc5, 0x82, 0x00], Keys::AltGr('l')), + ([0xc2, 0xb5, 0x00], Keys::AltGr('m')), + ([0xe2, 0x80, 0x9d], Keys::AltGr('n')), + ([0x7e, 0x00, 0x00], Keys::AltGr('ñ')), + ([0xc3, 0xb8, 0x00], Keys::AltGr('o')), + ([0xc3, 0xbe, 0x00], Keys::AltGr('p')), + ([0x40, 0x00, 0x00], Keys::AltGr('q')), + ([0xc2, 0xb6, 0x00], Keys::AltGr('r')), + ([0xc3, 0x9f, 0x00], Keys::AltGr('s')), + ([0xc5, 0xa7, 0x00], Keys::AltGr('t')), + ([0xe2, 0x86, 0x93], Keys::AltGr('u')), + ([0xe2, 0x80, 0x9e], Keys::AltGr('v')), + ([0xc5, 0xbf, 0x00], Keys::AltGr('w')), + ([0xc2, 0xbb, 0x00], Keys::AltGr('x')), + ([0xe2, 0x86, 0x90], Keys::AltGr('y')), + ([0xc2, 0xab, 0x00], Keys::AltGr('z')), +]; diff --git a/src/lib.rs b/src/lib.rs index 97e0d7b..0da2b3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,7 @@ pub fn get_key_from_keyboard() -> Keys { } } - #[cfg(feature = "standar")] + #[cfg(any(feature = "standar", feature = "full"))] for &(ref pattern, keys) in crate::keys::STANDAR.iter() { if buffer == *pattern { restore(&termios_enviroment); @@ -120,7 +120,7 @@ pub fn get_key_from_keyboard() -> Keys { } } - #[cfg(feature = "numbers")] + #[cfg(any(feature = "numbers", feature = "full"))] for &(ref pattern, keys) in crate::keys::NUMBERS.iter() { if buffer == *pattern { restore(&termios_enviroment); @@ -128,7 +128,7 @@ pub fn get_key_from_keyboard() -> Keys { } } - #[cfg(feature = "lower_letter")] + #[cfg(any(feature = "lower_letter", feature = "full"))] for &(ref pattern, keys) in crate::keys::LOWER_LETTERS.iter() { if buffer == *pattern { restore(&termios_enviroment); @@ -136,7 +136,7 @@ pub fn get_key_from_keyboard() -> Keys { } } - #[cfg(feature = "upper_letter")] + #[cfg(any(feature = "upper_letter", feature = "full"))] for &(ref pattern, keys) in crate::keys::UPPER_LETTER.iter() { if buffer == *pattern { restore(&termios_enviroment); @@ -144,7 +144,7 @@ pub fn get_key_from_keyboard() -> Keys { } } - #[cfg(feature = "f")] + #[cfg(any(feature = "f", feature = "full"))] for &(ref pattern, keys) in crate::keys::F.iter() { if buffer == *pattern { restore(&termios_enviroment); @@ -152,7 +152,7 @@ pub fn get_key_from_keyboard() -> Keys { } } - #[cfg(feature = "ctrl_lower_letter")] + #[cfg(any(feature = "ctrl_lower_letter", feature = "full"))] for &(ref pattern, keys) in crate::keys::CTRL_LOWER_LETTER.iter() { if buffer == *pattern { restore(&termios_enviroment); @@ -160,7 +160,7 @@ pub fn get_key_from_keyboard() -> Keys { } } - #[cfg(feature = "alt_lower_letter")] + #[cfg(any(feature = "alt_lower_letter", feature = "full"))] for &(ref pattern, keys) in crate::keys::ALT_LOWER_LETTER.iter() { if buffer == *pattern { restore(&termios_enviroment); @@ -168,6 +168,22 @@ pub fn get_key_from_keyboard() -> Keys { } } + #[cfg(any(feature = "alt_upper_letter", feature = "full"))] + for &(ref pattern, keys) in crate::keys::ALT_UPPER_LETTER.iter() { + if buffer == *pattern { + restore(&termios_enviroment); + key = keys; + } + } + + #[cfg(any(feature = "alt_gr_lower_letter", feature = "full"))] + for &(ref pattern, keys) in crate::keys::ALT_GR_LETTER.iter() { + if buffer == *pattern { + restore(&termios_enviroment); + key = keys; + } + } + restore(&termios_enviroment); key }