From e321dfc3c96f50f09c3953340a5a6fea72a5a245 Mon Sep 17 00:00:00 2001 From: Jiayi Zhao Date: Mon, 2 Mar 2020 18:50:29 -0500 Subject: add tab widget for showing which tab we are on - code cleanup - pageup and pagedown now work properly --- src/commands/open_file.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/commands/open_file.rs') diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index ee70151..39524e7 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -4,7 +4,6 @@ use crate::commands::{ChangeDirectory, JoshutoCommand, JoshutoRunnable}; use crate::config::mimetype::JoshutoMimetypeEntry; use crate::context::JoshutoContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; -use crate::history::DirectoryHistory; use crate::ui::widgets::{TuiMenu, TuiTextField}; use crate::ui::TuiBackend; use crate::util::load_child::LoadChild; @@ -59,6 +58,7 @@ impl OpenFile { options[0].execute_with(&paths)?; backend.terminal_restore(); } else { + OpenFileWith::open_with(context, backend, &paths)?; } } Ok(()) @@ -91,7 +91,11 @@ impl OpenFileWith { "open_file_with" } - pub fn open_with(context: &JoshutoContext, backend: &mut TuiBackend, paths: &[&PathBuf]) -> std::io::Result<()> { + pub fn open_with( + context: &JoshutoContext, + backend: &mut TuiBackend, + paths: &[&PathBuf], + ) -> std::io::Result<()> { const PROMPT: &'static str = "open_with "; let mimetype_options: Vec<&JoshutoMimetypeEntry> = OpenFile::get_options(&paths[0]); @@ -102,10 +106,7 @@ impl OpenFileWith { .enumerate() .map(|(i, e)| format!(" {} | {}", i, e)) .collect(); - let menu_options_str: Vec<&str> = menu_options - .iter() - .map(|e| e.as_str()) - .collect(); + let menu_options_str: Vec<&str> = menu_options.iter().map(|e| e.as_str()).collect(); let mut menu_widget = TuiMenu::new(&menu_options_str); let mut textfield = TuiTextField::default() @@ -121,8 +122,8 @@ impl OpenFileWith { match user_input.parse::() { Ok(n) if n >= mimetype_options.len() => Err(std::io::Error::new( - std::io::ErrorKind::InvalidData, - "option does not exist".to_owned(), + std::io::ErrorKind::InvalidData, + "option does not exist".to_owned(), )), Ok(n) => { let mimetype_entry = &mimetype_options[n]; @@ -167,9 +168,7 @@ impl std::fmt::Display for OpenFileWith { impl JoshutoRunnable for OpenFileWith { fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { let paths = match &context.tabs[context.curr_tab_index].curr_list_ref() { - Some(curr_list) => { - curr_list.get_selected_paths() - } + Some(curr_list) => curr_list.get_selected_paths(), None => vec![], }; @@ -177,7 +176,7 @@ impl JoshutoRunnable for OpenFileWith { return Err(JoshutoError::new( JoshutoErrorKind::IONotFound, String::from("No files selected"), - )) + )); } Self::open_with(context, backend, &paths)?; Ok(()) -- cgit v1.2.3