aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/client/event.rs
diff options
context:
space:
mode:
authorFrank Hamand <frank.hamand@coinbase.com>2022-06-13 09:33:05 +0100
committerGitHub <noreply@github.com>2022-06-13 09:33:05 +0100
commitab994e3c827c65966ebc9cd2ac1d3a6048f042bc (patch)
tree5b0cd9d58b5f41caca9e6d758abb99fb372c5a28 /src/command/client/event.rs
parentAdd configurable history length (#447) (diff)
downloadatuin-ab994e3c827c65966ebc9cd2ac1d3a6048f042bc.zip
Batch key handling (#448)
* Batch input events and only query once they are finished This simplifies the code a lot (no more bounded channel) and yields the same performance improvement with scroll wheel spam while fixing copy/paste * Clippy * fmt * Use blocking wait before emptying events channel This was causing a busy loop * Update query on filter mode change
Diffstat (limited to '')
-rw-r--r--src/command/client/event.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/command/client/event.rs b/src/command/client/event.rs
index f818d728..8044e278 100644
--- a/src/command/client/event.rs
+++ b/src/command/client/event.rs
@@ -1,6 +1,6 @@
use std::{thread, time::Duration};
-use crossbeam_channel::{bounded, TrySendError};
+use crossbeam_channel::unbounded;
use termion::{event::Event as TermEvent, event::Key, input::TermRead};
pub enum Event<I> {
@@ -35,22 +35,16 @@ impl Events {
}
pub fn with_config(config: Config) -> Events {
- // Keep channel small so scroll events don't stack for ages.
- let (tx, rx) = bounded(1);
+ let (tx, rx) = unbounded();
{
let tx = tx.clone();
thread::spawn(move || {
let tty = termion::get_tty().expect("Could not find tty");
for event in tty.events().flatten() {
- if let Err(err) = tx.try_send(Event::Input(event)) {
- if let TrySendError::Full(_) = err {
- // Silently ignore send fails when buffer is full.
- // This will most likely be scroll wheel spam and we can drop some events.
- } else {
- eprintln!("{}", err);
- return;
- }
+ if let Err(err) = tx.send(Event::Input(event)) {
+ eprintln!("{}", err);
+ return;
}
}
})
@@ -69,4 +63,8 @@ impl Events {
pub fn next(&self) -> Result<Event<TermEvent>, crossbeam_channel::RecvError> {
self.rx.recv()
}
+
+ pub fn try_next(&self) -> Result<Event<TermEvent>, crossbeam_channel::TryRecvError> {
+ self.rx.try_recv()
+ }
}