summaryrefslogtreecommitdiffstats
path: root/src/util/event.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-12-13 12:42:53 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-12-13 12:42:53 -0500
commit2e5cdd07c2d8c18bad4099c82e36af64dc473a64 (patch)
treea9d7dee0f5a603cc96d6415a4549436a0f1818e0 /src/util/event.rs
parent468e607c5d1cd5d554ae356fd3c8e78425840347 (diff)
code cleanup and fix path not showing when too long
Diffstat (limited to 'src/util/event.rs')
-rw-r--r--src/util/event.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/util/event.rs b/src/util/event.rs
index f019b80..3d89503 100644
--- a/src/util/event.rs
+++ b/src/util/event.rs
@@ -41,36 +41,34 @@ impl Events {
let (input_tx, input_rx) = mpsc::sync_channel(1);
let (event_tx, event_rx) = mpsc::channel();
- {
- let event_tx = event_tx.clone();
- thread::spawn(move || {
- let stdin = io::stdin();
- let mut keys = stdin.keys();
- match keys.next() {
- Some(key) => match key {
- Ok(key) => {
- if let Err(e) = event_tx.send(Event::Input(key)) {
- eprintln!("Input thread send err: {:#?}", e);
- return;
- }
+ let event_tx2 = event_tx.clone();
+ thread::spawn(move || {
+ let stdin = io::stdin();
+ let mut keys = stdin.keys();
+ match keys.next() {
+ Some(key) => match key {
+ Ok(key) => {
+ if let Err(e) = event_tx2.send(Event::Input(key)) {
+ eprintln!("Input thread send err: {:#?}", e);
+ return;
}
- _ => return,
- },
+ }
_ => return,
- }
+ },
+ _ => return,
+ }
- while let Ok(_) = input_rx.recv() {
- if let Some(key) = keys.next() {
- if let Ok(key) = key {
- if let Err(e) = event_tx.send(Event::Input(key)) {
- eprintln!("Input thread send err: {:#?}", e);
- return;
- }
+ while input_rx.recv().is_ok() {
+ if let Some(key) = keys.next() {
+ if let Ok(key) = key {
+ if let Err(e) = event_tx2.send(Event::Input(key)) {
+ eprintln!("Input thread send err: {:#?}", e);
+ return;
}
}
}
- })
- };
+ }
+ });
Events {
event_tx,