diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/event.rs | 26 | ||||
-rw-r--r-- | src/util/sort.rs | 23 |
2 files changed, 27 insertions, 22 deletions
diff --git a/src/util/event.rs b/src/util/event.rs index b3955a6..895dc56 100644 --- a/src/util/event.rs +++ b/src/util/event.rs @@ -42,22 +42,26 @@ impl Events { { 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 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; + } } - } + _ => return, + }, _ => return, - }, - _ => return, + } } while let Ok(_) = input_rx.recv() { + let stdin = io::stdin(); + let mut keys = stdin.keys(); if let Some(key) = keys.next() { if let Ok(key) = key { if let Err(e) = event_tx.send(Event::Input(key)) { diff --git a/src/util/sort.rs b/src/util/sort.rs index d290895..892810b 100644 --- a/src/util/sort.rs +++ b/src/util/sort.rs @@ -43,6 +43,18 @@ pub struct SortOption { impl SortOption { pub fn compare_func(&self) -> impl Fn(&JoshutoDirEntry, &JoshutoDirEntry) -> cmp::Ordering { + let dir_cmp = if self.directories_first { + dir_first + } else { + dummy_dir_first + }; + + let rev_cmp = if self.reverse { + reverse_ordering + } else { + dummy_reverse + }; + let base_cmp = match self.sort_method { SortType::Natural => { if self.case_sensitive { @@ -61,17 +73,6 @@ impl SortOption { SortType::Mtime => mtime_sort, }; - let rev_cmp = if self.reverse { - reverse_ordering - } else { - dummy_reverse - }; - let dir_cmp = if self.directories_first { - dir_first - } else { - dummy_dir_first - }; - move |f1, f2| dir_cmp(f1, f2).then_with(|| rev_cmp(base_cmp(f1, f2))) } |