fix(keymaps/crossterm): Implement it fully
This commit is contained in:
parent
f3b3cada71
commit
5f69311dfa
|
@ -38,3 +38,9 @@ pub enum KeyValueParseError {
|
||||||
#[error("The number associate with the F key ('{0}') can't be parsed as u8!")]
|
#[error("The number associate with the F key ('{0}') can't be parsed as u8!")]
|
||||||
CantParseFNumber(#[from] ParseIntError),
|
CantParseFNumber(#[from] ParseIntError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub enum KeyFromCrossterm {
|
||||||
|
#[error("Can not parse non Key event to a Key code: ('{0:?}')")]
|
||||||
|
OnlyKey(crossterm::event::Event),
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use log::{debug, info};
|
|
||||||
|
|
||||||
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};
|
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};
|
||||||
|
|
||||||
|
use crate::{error, key_repr::KeyValue};
|
||||||
|
|
||||||
|
use super::Key;
|
||||||
|
|
||||||
impl Into<Event> for Key {
|
impl Into<Event> for Key {
|
||||||
fn into(self) -> Event {
|
fn into(self) -> Event {
|
||||||
let mut modifiers;
|
let mut modifiers;
|
||||||
|
@ -43,9 +45,8 @@ impl Into<Event> for Key {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(crossterm)]
|
|
||||||
impl TryFrom<&Event> for Key {
|
impl TryFrom<&Event> for Key {
|
||||||
type Error = anyhow::Error;
|
type Error = error::KeyFromCrossterm;
|
||||||
|
|
||||||
fn try_from(value: &Event) -> std::result::Result<Self, Self::Error> {
|
fn try_from(value: &Event) -> std::result::Result<Self, Self::Error> {
|
||||||
let mut output_key: Key = Key::new();
|
let mut output_key: Key = Key::new();
|
||||||
|
@ -69,11 +70,7 @@ impl TryFrom<&Event> for Key {
|
||||||
|
|
||||||
Ok(output_key)
|
Ok(output_key)
|
||||||
}
|
}
|
||||||
Event::Mouse(_)
|
event => Err(error::KeyFromCrossterm::OnlyKey(event.to_owned())),
|
||||||
| Event::Paste(_)
|
|
||||||
| Event::Resize(_, _)
|
|
||||||
| Event::FocusGained
|
|
||||||
| Event::FocusLost => bail!("Only supports parsing from key event"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[cfg(crossterm)]
|
#[cfg(feature = "crossterm")]
|
||||||
mod crossterm;
|
mod crossterm;
|
||||||
|
|
||||||
mod parsing;
|
mod parsing;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use crossterm::event::KeyCode;
|
use crossterm::event::KeyCode;
|
||||||
|
|
||||||
|
use super::KeyValue;
|
||||||
|
|
||||||
impl From<KeyCode> for KeyValue {
|
impl From<KeyCode> for KeyValue {
|
||||||
fn from(value: KeyCode) -> Self {
|
fn from(value: KeyCode) -> Self {
|
||||||
match value {
|
match value {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[cfg(crossterm)]
|
#[cfg(feature = "crossterm")]
|
||||||
mod crossterm;
|
mod crossterm;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
|
Reference in New Issue