too/backend/events/
key.rs#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Key {
Char(char),
Function(u8),
Left,
Right,
Up,
Down,
PageUp,
PageDown,
Home,
End,
Insert,
Enter,
Delete,
Backspace,
Escape,
Tab,
}
impl Key {
pub const fn is_char(&self, ch: char) -> bool {
if let &Self::Char(c) = self {
return c == ch;
}
false
}
pub fn to_ascii_uppercase(&self) -> Option<Self> {
let Self::Char(ch) = self else { return None };
ch.is_ascii()
.then(|| ch.to_ascii_uppercase())
.map(Self::Char)
}
pub fn to_ascii_lowercase(&self) -> Option<Self> {
let Self::Char(ch) = self else { return None };
ch.is_ascii()
.then(|| ch.to_ascii_lowercase())
.map(Self::Char)
}
pub const fn is_ascii_uppercase(&self) -> bool {
let Self::Char(ch) = self else { return false };
ch.is_ascii_uppercase()
}
pub const fn is_ascii_lowercase(&self) -> bool {
let Self::Char(ch) = self else { return false };
ch.is_ascii_lowercase()
}
}