diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config/mimetype.rs | 2 | ||||
-rw-r--r-- | src/fs/dirlist.rs | 52 | ||||
-rw-r--r-- | src/run.rs | 3 | ||||
-rw-r--r-- | src/ui/tui_backend.rs | 4 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 1 | ||||
-rw-r--r-- | src/ui/widgets/tui_view.rs | 8 | ||||
-rw-r--r-- | src/util/event.rs | 26 | ||||
-rw-r--r-- | src/util/sort.rs | 23 |
8 files changed, 54 insertions, 65 deletions
diff --git a/src/config/mimetype.rs b/src/config/mimetype.rs index e6103dd..ce542ff 100644 --- a/src/config/mimetype.rs +++ b/src/config/mimetype.rs @@ -125,7 +125,7 @@ impl std::fmt::Display for JoshutoMimetypeEntry { .iter() .for_each(|arg| write!(f, " {}", arg).unwrap()); - f.write_str("\t\t").unwrap(); + f.write_str(" ").unwrap(); if self.get_fork() { f.write_str("[fork]").unwrap(); } diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs index d636b2b..806377c 100644 --- a/src/fs/dirlist.rs +++ b/src/fs/dirlist.rs @@ -48,29 +48,27 @@ impl JoshutoDirList { pub fn reload_contents(&mut self, sort_option: &SortOption) -> std::io::Result<()> { let filter_func = sort_option.filter_func(); - let mut contents = read_dir_list(&self.path, filter_func)?; let sort_func = sort_option.compare_func(); + + let mut contents = read_dir_list(&self.path, filter_func)?; contents.sort_by(sort_func); let contents_len = contents.len(); - - let index: Option<usize> = { - if contents_len == 0 { - None - } else { - match self.index { - Some(i) if i >= contents_len => Some(contents_len - 1), - Some(i) => { - let entry = &self.contents[i]; - contents - .iter() - .enumerate() - .find(|(_, e)| e.file_name() == entry.file_name()) - .map(|(i, _)| i) - .or(Some(i)) - } - None => Some(0), + let index: Option<usize> = if contents_len == 0 { + None + } else { + match self.index { + Some(i) if i >= contents_len => Some(contents_len - 1), + Some(i) => { + let entry = &self.contents[i]; + contents + .iter() + .enumerate() + .find(|(_, e)| e.file_name() == entry.file_name()) + .map(|(i, _)| i) + .or(Some(i)) } + None => Some(0), } }; @@ -130,23 +128,7 @@ where { let results: Vec<JoshutoDirEntry> = fs::read_dir(path)? .filter(filter_func) - .filter_map(map_entry_default) + .filter_map(|res| JoshutoDirEntry::from(&res.ok()?).ok()) .collect(); Ok(results) } - -fn map_entry_default(result: std::io::Result<fs::DirEntry>) -> Option<JoshutoDirEntry> { - match result { - Ok(direntry) => match JoshutoDirEntry::from(&direntry) { - Ok(s) => Some(s), - Err(e) => { - eprintln!("Entry: {:?}, {:?}", direntry, e); - None - } - }, - Err(e) => { - eprintln!("{:?}", e); - None - } - } -} @@ -51,7 +51,7 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io: match event { Event::IOWorkerProgress(p) => { - context.worker_msg = Some(format!("bytes copied {}", p)); + context.worker_msg = Some(format!("{} copied", format::file_size_to_string(p))); } Event::IOWorkerResult(res) => { match io_observer { @@ -118,5 +118,6 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io: let mut view = TuiView::new(&context); backend.render(&mut view); } + Ok(()) } diff --git a/src/ui/tui_backend.rs b/src/ui/tui_backend.rs index 7d3a7f3..a7d7152 100644 --- a/src/ui/tui_backend.rs +++ b/src/ui/tui_backend.rs @@ -14,8 +14,8 @@ pub struct TuiBackend { impl TuiBackend { pub fn new() -> std::io::Result<Self> { let stdout = std::io::stdout().into_raw_mode()?; - let stdout = AlternateScreen::from(stdout); - let backend = TermionBackend::new(stdout); + let alt_screen = AlternateScreen::from(stdout); + let backend = TermionBackend::new(alt_screen); let mut terminal = tui::Terminal::new(backend)?; terminal.hide_cursor()?; Ok(Self { diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index ac7da28..1e40cbd 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -68,6 +68,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> { buf.set_stringn(x, y + i as u16, name, area_width - 1, style); buf.set_string(x + area_width as u16 - 1, y + i as u16, "…", style); } + // TODO: print out symlink path // } else if file_type.is_symlink() { } else { if name_width < area_width - FILE_SIZE_WIDTH { diff --git a/src/ui/widgets/tui_view.rs b/src/ui/widgets/tui_view.rs index 72ff38c..cc6e1b2 100644 --- a/src/ui/widgets/tui_view.rs +++ b/src/ui/widgets/tui_view.rs @@ -105,12 +105,12 @@ impl<'a> Widget for TuiView<'a> { if self.show_bottom_status { /* draw the bottom status bar */ - if let Some(msg) = self.context.worker_msg.as_ref() { - let text = [Text::styled(msg, message_style)]; + if !self.context.message_queue.is_empty() { + let text = [Text::styled(&self.context.message_queue[0], message_style)]; Paragraph::new(text.iter()).wrap(true).draw(rect, buf); - } else if !self.context.message_queue.is_empty() { - let text = [Text::styled(&self.context.message_queue[0], message_style)]; + } else if let Some(msg) = self.context.worker_msg.as_ref() { + let text = [Text::styled(msg, message_style)]; Paragraph::new(text.iter()).wrap(true).draw(rect, buf); } else if let Some(entry) = curr_list.get_curr_ref() { 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))) } |