summaryrefslogtreecommitdiffstats
path: root/src/commands/open_file.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-02 18:50:29 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-02 18:50:29 -0500
commite321dfc3c96f50f09c3953340a5a6fea72a5a245 (patch)
treedc13fee011e7c49536eb28b5b3d5de8bef93af89 /src/commands/open_file.rs
parent8bc73974e78883eb1f619d1829a8be77933e5c00 (diff)
add tab widget for showing which tab we are on
- code cleanup - pageup and pagedown now work properly
Diffstat (limited to 'src/commands/open_file.rs')
-rw-r--r--src/commands/open_file.rs23
1 files changed, 11 insertions, 12 deletions
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::<usize>() {
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(())