|
|
|
@ -1,4 +1,13 @@
|
|
|
|
|
type Code = u16;
|
|
|
|
|
// type Code = u16;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
|
|
|
|
pub struct Code {
|
|
|
|
|
/// The integer value of the keycode
|
|
|
|
|
pub val: u16,
|
|
|
|
|
|
|
|
|
|
/// The unicode symbol that represents the keycode, if any
|
|
|
|
|
pub sym: Option<char>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Event {
|
|
|
|
@ -26,54 +35,35 @@ pub struct Event {
|
|
|
|
|
|
|
|
|
|
impl Event {}
|
|
|
|
|
|
|
|
|
|
impl std::fmt::Display for Event {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
if self.shift {
|
|
|
|
|
if self.ctrl {
|
|
|
|
|
if self.alt {
|
|
|
|
|
// write!(f, "⇧⎈⎇ {}", self.char)
|
|
|
|
|
write!(f, "<S-C-A-{}>", self.char)
|
|
|
|
|
} else {
|
|
|
|
|
// write!(f, "⇧⎈ {}", self.char)
|
|
|
|
|
write!(f, "<S-C-{}>", self.char)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if self.alt {
|
|
|
|
|
// write!(f, "⇧⎇ {}", self.char)
|
|
|
|
|
write!(f, "<S-A-{}>", self.char)
|
|
|
|
|
} else {
|
|
|
|
|
write!(f, "<S-{}>", self.char)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if self.ctrl {
|
|
|
|
|
if self.alt {
|
|
|
|
|
// write!(f, "⎈⎇ {}", self.char)
|
|
|
|
|
write!(f, "<C-A-{}>", self.char)
|
|
|
|
|
} else {
|
|
|
|
|
// write!(f, "⎈ {}", self.char)
|
|
|
|
|
write!(f, "<C-{}>", self.char)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if self.alt {
|
|
|
|
|
// write!(f, "⎇ {}", self.char)
|
|
|
|
|
write!(f, "<A-{}>", self.char)
|
|
|
|
|
} else {
|
|
|
|
|
write!(f, "{}", self.char)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// CODES contains a lookup table for key codes. Note that this is a sparse array and not all
|
|
|
|
|
/// values associate to valid key codes.
|
|
|
|
|
pub static CODES: [Code; 256] = gen_codes();
|
|
|
|
|
|
|
|
|
|
macro_rules! keycodes {
|
|
|
|
|
($($val:literal $name:ident $sym:literal)*) => {
|
|
|
|
|
const fn gen_codes() -> [Code; 256] {
|
|
|
|
|
let mut codes = [Code{val: 0, sym: None}; 256];
|
|
|
|
|
let mut i = 0 as usize;
|
|
|
|
|
while i < 256 {
|
|
|
|
|
codes[i] = Code{val: i as u16, sym: None};
|
|
|
|
|
i = i + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(
|
|
|
|
|
codes[$val] = Code{val: $val, sym: Some($sym)};
|
|
|
|
|
)*
|
|
|
|
|
codes
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
macro_rules! keycodes {
|
|
|
|
|
($($c:literal $n:ident $x:literal)*) => {$(
|
|
|
|
|
$(
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
pub const $n: Code = $c;
|
|
|
|
|
)*};
|
|
|
|
|
pub const $name: Code = Code{val: $val, sym: Some($sym)};
|
|
|
|
|
)*
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keycodes! {
|
|
|
|
|
0x07 NOTBACKSPACE '⌫'
|
|
|
|
|
0x08 BACKSPACE '⌫'
|
|
|
|
|
0x09 TAB '↹'
|
|
|
|
|
// 0x0A-0B Reserved
|
|
|
|
|