diff options
| author | Conrad Ludgate <conradludgate@gmail.com> | 2023-02-10 17:25:43 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-10 17:25:43 +0000 |
| commit | edda1b741a4a0816eb6e62eafd69fc9896603cf5 (patch) | |
| tree | cc5cb45caecc4fbe6b34e08f2347fdfdf897d0b5 /src/command/client/search/event.rs | |
| parent | Bump debian from bullseye-20221205-slim to bullseye-20230208-slim (#701) (diff) | |
| download | atuin-edda1b741a4a0816eb6e62eafd69fc9896603cf5.zip | |
crossterm support (#331)
* crossterm v2
* patch crossterm
* fix-version
* no more tui dependency
* lints
Diffstat (limited to 'src/command/client/search/event.rs')
| -rw-r--r-- | src/command/client/search/event.rs | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/src/command/client/search/event.rs b/src/command/client/search/event.rs deleted file mode 100644 index 0e791c96..00000000 --- a/src/command/client/search/event.rs +++ /dev/null @@ -1,70 +0,0 @@ -use std::{thread, time::Duration}; - -use crossbeam_channel::unbounded; -use termion::{event::Event as TermEvent, event::Key, input::TermRead}; - -pub enum Event<I> { - Input(I), - Tick, -} - -/// A small event handler that wrap termion input and tick events. Each event -/// type is handled in its own thread and returned to a common `Receiver` -pub struct Events { - rx: crossbeam_channel::Receiver<Event<TermEvent>>, -} - -#[derive(Debug, Clone, Copy)] -pub struct Config { - pub exit_key: Key, - pub tick_rate: Duration, -} - -impl Default for Config { - fn default() -> Config { - Config { - exit_key: Key::Char('q'), - tick_rate: Duration::from_millis(250), - } - } -} - -impl Events { - pub fn new() -> Events { - Events::with_config(Config::default()) - } - - pub fn with_config(config: Config) -> Events { - 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.send(Event::Input(event)) { - eprintln!("{err}"); - return; - } - } - }) - }; - - thread::spawn(move || loop { - if tx.send(Event::Tick).is_err() { - break; - } - thread::sleep(config.tick_rate); - }); - - Events { rx } - } - - 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() - } -} |
