Skip to content

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mateolafalce committed Dec 25, 2023
1 parent c162411 commit 5d536ad
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 11 deletions.
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <mateolafalce@protonmail.com>"]
description = "A keyboard event handler that allows dynamic development"
keywords = ["keyboard", "terminal", "tui", "tty", "termios"]
repository = "https://github.com/mateolafalce/k_board"
Expand All @@ -20,4 +20,7 @@ lower_letter = []
upper_letter = []
f = []
ctrl_lower_letter = []
alt_lower_letter = []
alt_lower_letter = []
alt_upper_letter = []
alt_gr_letter = []
full = []
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum Keys {
F(u8),
Ctrl(char),
Alt(char),
AltGr(char),
Null,
}
```
Expand Down Expand Up @@ -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

<details>
<summary>no-feature(default)</summary>
Expand Down Expand Up @@ -353,4 +357,87 @@ pub const ALT_LOWER_LETTER: [([u8; BYTES], Keys); 27] = [
([0x1b, 0x7a, 0x00], Keys::Alt('z')),
];
```
</details>


<details>
<summary>alt_upper_letter</summary>

```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')),
];
```

<details>
<summary>alt_gr_letter</summary>

```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')),
];
```

</details>


</details>

<details>
<summary>full</summary>

all features!

</details>
61 changes: 61 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Keys {
F(u8),
Ctrl(char),
Alt(char),
AltGr(char),
Null,
}

Expand Down Expand Up @@ -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')),
];
30 changes: 23 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,62 +112,78 @@ 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);
key = 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);
key = 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);
key = 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);
key = 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);
key = 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);
key = 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);
key = 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
}

0 comments on commit 5d536ad

Please sign in to comment.