From e5960b8eda23b59a75540d9060176f0185508ba8 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 28 Apr 2023 15:51:19 +0200 Subject: [PATCH] Include more things in InputEvent --- Cargo.lock | 2 ++ Cargo.toml | 5 +++++ cove-input/Cargo.toml | 2 ++ cove-input/src/lib.rs | 41 ++++++++++++++++++++++++----------------- cove/Cargo.toml | 7 ++----- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bac6134..71de4e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,9 +294,11 @@ version = "0.6.1" dependencies = [ "cove-macro", "crossterm", + "parking_lot", "serde", "serde_either", "thiserror", + "toss", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 33e3c2c..df60d72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/cove-input/Cargo.toml b/cove-input/Cargo.toml index 61e178f..63567d6 100644 --- a/cove-input/Cargo.toml +++ b/cove-input/Cargo.toml @@ -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} diff --git a/cove-input/src/lib.rs b/cove-input/src/lib.rs index ef0a0aa..62063e6 100644 --- a/cove-input/src/lib.rs +++ b/cove-input/src/lib.rs @@ -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>, } -impl InputEvent { - pub fn from_crossterm_event(event: crossterm::event::Event) -> Option { - 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>, + ) -> Self { + Self { + event, + terminal, + crossterm_lock, } } pub fn key_event(&self) -> Option { - 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(&self, binding: &KeyBinding) -> bool { + pub fn matches(&self, binding: &KeyBinding) -> bool { match self.key_event() { Some(event) => binding.matches(event), None => false, diff --git a/cove/Cargo.toml b/cove/Cargo.toml index 6db9df3..2cc76d3 100644 --- a/cove/Cargo.toml +++ b/cove/Cargo.toml @@ -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"