Include more things in InputEvent
This commit is contained in:
parent
6b05a2a06d
commit
e5960b8eda
5 changed files with 35 additions and 22 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -294,9 +294,11 @@ version = "0.6.1"
|
|||
dependencies = [
|
||||
"cove-macro",
|
||||
"crossterm",
|
||||
"parking_lot",
|
||||
"serde",
|
||||
"serde_either",
|
||||
"thiserror",
|
||||
"toss",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -8,9 +8,14 @@ edition = "2021"
|
|||
|
||||
[workspace.dependencies]
|
||||
crossterm = "0.26.1"
|
||||
parking_lot = "0.12.1"
|
||||
serde = { version = "1.0.159", features = ["derive"] }
|
||||
serde_either = "0.2.1"
|
||||
thiserror = "1.0.40"
|
||||
|
||||
[workspace.dependencies.toss]
|
||||
git = "https://github.com/Garmelon/toss.git"
|
||||
rev = "8bfb4b2dc345c3e0ffdb89bdb34f2996487a35cb"
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ edition = { workspace = true }
|
|||
cove-macro = { path = "../cove-macro" }
|
||||
|
||||
crossterm = { workspace = true }
|
||||
parking_lot = {workspace = true}
|
||||
serde = { workspace = true }
|
||||
serde_either = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
toss = {workspace = true}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
mod keys;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use cove_macro::KeyGroup;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::{Event, KeyEvent};
|
||||
use parking_lot::FairMutex;
|
||||
use toss::Terminal;
|
||||
|
||||
pub use crate::keys::*;
|
||||
|
||||
|
|
@ -10,37 +14,40 @@ pub trait KeyGroup {
|
|||
fn bindings(&self) -> Vec<(&KeyBinding, &'static str)>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum InputEvent {
|
||||
Key(KeyEvent),
|
||||
Paste(String),
|
||||
pub struct InputEvent<'a> {
|
||||
event: crossterm::event::Event,
|
||||
terminal: &'a mut Terminal,
|
||||
crossterm_lock: Arc<FairMutex<()>>,
|
||||
}
|
||||
|
||||
impl InputEvent {
|
||||
pub fn from_crossterm_event(event: crossterm::event::Event) -> Option<Self> {
|
||||
use crossterm::event::Event::*;
|
||||
match event {
|
||||
Key(event) => Some(Self::Key(event)),
|
||||
Paste(string) => Some(Self::Paste(string)),
|
||||
_ => None,
|
||||
impl<'a> InputEvent<'a> {
|
||||
pub fn new(
|
||||
event: Event,
|
||||
terminal: &'a mut Terminal,
|
||||
crossterm_lock: Arc<FairMutex<()>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
event,
|
||||
terminal,
|
||||
crossterm_lock,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn key_event(&self) -> Option<KeyEvent> {
|
||||
match self {
|
||||
Self::Key(event) => Some(*event),
|
||||
match &self.event {
|
||||
Event::Key(event) => Some(*event),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paste_event(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Paste(string) => Some(string),
|
||||
match &self.event {
|
||||
Event::Paste(string) => Some(string),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn matches<S: ToString>(&self, binding: &KeyBinding) -> bool {
|
||||
pub fn matches(&self, binding: &KeyBinding) -> bool {
|
||||
match self.key_event() {
|
||||
Some(event) => binding.matches(event),
|
||||
None => false,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ cove-config = { path = "../cove-config" }
|
|||
cove-input = { path = "../cove-input" }
|
||||
|
||||
crossterm = { workspace = true }
|
||||
parking_lot = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
toss = { workspace = true }
|
||||
|
||||
anyhow = "1.0.70"
|
||||
async-trait = "0.1.68"
|
||||
|
|
@ -20,7 +22,6 @@ linkify = "0.9.0"
|
|||
log = { version = "0.4.17", features = ["std"] }
|
||||
once_cell = "1.17.1"
|
||||
open = "4.0.1"
|
||||
parking_lot = "0.12.1"
|
||||
rusqlite = { version = "0.29.0", features = ["bundled", "time"] }
|
||||
serde_json = "1.0.95"
|
||||
tokio = { version = "1.27.0", features = ["full"] }
|
||||
|
|
@ -40,10 +41,6 @@ git = "https://github.com/Garmelon/euphoxide.git"
|
|||
rev = "0f217a6279181b0731216760219e8ff0fa01e449"
|
||||
features = ["bot"]
|
||||
|
||||
[dependencies.toss]
|
||||
git = "https://github.com/Garmelon/toss.git"
|
||||
rev = "8bfb4b2dc345c3e0ffdb89bdb34f2996487a35cb"
|
||||
|
||||
[dependencies.vault]
|
||||
git = "https://github.com/Garmelon/vault.git"
|
||||
rev = "b4cf23b7279770226725c895e482c8eda88c43a7"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue