summaryrefslogtreecommitdiffstats
path: root/src/commands
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
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')
-rw-r--r--src/commands/cursor_move.rs20
-rw-r--r--src/commands/delete_files.rs2
-rw-r--r--src/commands/new_directory.rs2
-rw-r--r--src/commands/open_file.rs23
-rw-r--r--src/commands/rename_file.rs3
-rw-r--r--src/commands/set_mode.rs1
-rw-r--r--src/commands/tab_operations.rs4
-rw-r--r--src/commands/tab_switch.rs12
8 files changed, 33 insertions, 34 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 36ba233..d249181 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -134,10 +134,16 @@ impl std::fmt::Display for CursorMovePageUp {
}
impl JoshutoRunnable for CursorMovePageUp {
- fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ let half_page = {
+ match backend.terminal.as_ref().unwrap().size() {
+ Ok(rect) => rect.height as usize - 2,
+ _ => 10,
+ }
+ };
+
let movement = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => {
- let half_page = 10;
curr_list
.index
.map(|idx| if idx > half_page { idx - half_page } else { 0 })
@@ -173,11 +179,17 @@ impl std::fmt::Display for CursorMovePageDown {
}
impl JoshutoRunnable for CursorMovePageDown {
- fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ let half_page = {
+ match backend.terminal.as_ref().unwrap().size() {
+ Ok(rect) => rect.height as usize - 2,
+ _ => 10,
+ }
+ };
+
let movement = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => {
let dir_len = curr_list.contents.len();
- let half_page = 10;
curr_list.index.map(|idx| {
if idx + half_page > dir_len - 1 {
dir_len - 1
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index d89a17d..30a5754 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -1,5 +1,4 @@
use std::fs;
-use std::io::{self, Write};
use std::path;
use termion::event::Key;
@@ -8,7 +7,6 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::ui::TuiBackend;
-use crate::util::event::Event;
use crate::ui::widgets::TuiPrompt;
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index 2a72c38..ab7c170 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -28,7 +28,7 @@ impl std::fmt::Display for NewDirectory {
}
impl JoshutoRunnable for NewDirectory {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
for path in &self.paths {
std::fs::create_dir_all(path)?;
}
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(())
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index 8d666d3..23ae1fd 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -22,7 +22,6 @@ impl RenameFile {
&self,
path: &path::PathBuf,
context: &mut JoshutoContext,
- backend: &mut TuiBackend,
) -> std::io::Result<()> {
let new_path = &self.path;
if new_path.exists() {
@@ -58,7 +57,7 @@ impl JoshutoRunnable for RenameFile {
}
if let Some(path) = path {
- self.rename_file(&path, context, backend)?;
+ self.rename_file(&path, context)?;
}
Ok(())
}
diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs
index 94a6d23..4ff5343 100644
--- a/src/commands/set_mode.rs
+++ b/src/commands/set_mode.rs
@@ -2,7 +2,6 @@ use crate::commands::{CursorMoveDown, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::fs::JoshutoDirEntry;
-use crate::ui::widgets::TuiTextField;
use crate::ui::TuiBackend;
use crate::util::unix;
diff --git a/src/commands/tab_operations.rs b/src/commands/tab_operations.rs
index aae7371..c2bdbab 100644
--- a/src/commands/tab_operations.rs
+++ b/src/commands/tab_operations.rs
@@ -29,7 +29,7 @@ impl NewTab {
let tab = JoshutoTab::new(curr_path, &context.config_t.sort_option)?;
context.tabs.push(tab);
context.curr_tab_index = context.tabs.len() - 1;
- TabSwitch::tab_switch(context.curr_tab_index, context, backend)?;
+ TabSwitch::tab_switch(context.curr_tab_index, context)?;
Ok(())
}
}
@@ -68,7 +68,7 @@ impl CloseTab {
if context.curr_tab_index > 0 {
context.curr_tab_index -= 1;
}
- TabSwitch::tab_switch(context.curr_tab_index, context, backend)?;
+ TabSwitch::tab_switch(context.curr_tab_index, context)?;
Ok(())
}
}
diff --git a/src/commands/tab_switch.rs b/src/commands/tab_switch.rs
index a6dbab1..ef911f1 100644
--- a/src/commands/tab_switch.rs
+++ b/src/commands/tab_switch.rs
@@ -18,19 +18,11 @@ impl TabSwitch {
"tab_switch"
}
- pub fn tab_switch(
- new_index: usize,
- context: &mut JoshutoContext,
- backend: &mut TuiBackend,
- ) -> std::io::Result<()> {
+ pub fn tab_switch(new_index: usize, context: &mut JoshutoContext) -> std::io::Result<()> {
context.curr_tab_index = new_index;
let path = &context.curr_tab_ref().curr_path;
env::set_current_dir(path)?;
- /*
- ui::redraw_tab_view(&view.tab_win, &context);
- ncurses::doupdate();
- */
Ok(())
}
}
@@ -54,7 +46,7 @@ impl JoshutoRunnable for TabSwitch {
new_index -= tab_len;
}
let new_index = new_index as usize;
- Self::tab_switch(new_index, context, backend)?;
+ Self::tab_switch(new_index, context)?;
Ok(())
}
}