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