diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-03-30 15:11:08 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-03-30 15:11:08 -0400 |
commit | 554f06d72aeb639548314336b2318e14f8ffcc7e (patch) | |
tree | 4f3346fdd7b9302ccaa82089cd7eceff4d8b28de /src/commands/change_directory.rs | |
parent | f56511becd2be285ff2ce74269113384856aaa95 (diff) |
move view struct out of Context and pass in as a separate argument
- rename static variables to all caps
- change index to be Option<usize> rather than i32 where -1 means
the directory is empty
Diffstat (limited to 'src/commands/change_directory.rs')
-rw-r--r-- | src/commands/change_directory.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index 0b96145..ae77964 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -4,6 +4,7 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::preview; use crate::ui; +use crate::window::JoshutoView; #[derive(Clone, Debug)] pub struct ChangeDirectory { @@ -18,9 +19,13 @@ impl ChangeDirectory { "cd" } - pub fn change_directory(path: &path::PathBuf, context: &mut JoshutoContext) { + pub fn change_directory( + path: &path::PathBuf, + context: &mut JoshutoContext, + view: &JoshutoView, + ) { if !path.exists() { - ui::wprint_err(&context.views.bot_win, "Error: No such file or directory"); + ui::wprint_err(&view.bot_win, "Error: No such file or directory"); return; } let curr_tab = &mut context.tabs[context.curr_tab_index]; @@ -30,7 +35,7 @@ impl ChangeDirectory { curr_tab.curr_path = path.clone(); } Err(e) => { - ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); + ui::wprint_err(&view.bot_win, e.to_string().as_str()); return; } } @@ -50,7 +55,7 @@ impl ChangeDirectory { { Ok(s) => Some(s), Err(e) => { - ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); + ui::wprint_err(&view.bot_win, e.to_string().as_str()); None } }; @@ -62,14 +67,14 @@ impl ChangeDirectory { { Ok(s) => Some(s), Err(e) => { - ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); + ui::wprint_err(&view.bot_win, e.to_string().as_str()); None } }; } curr_tab.refresh( - &context.views, + view, &context.config_t, &context.username, &context.hostname, @@ -86,11 +91,11 @@ impl std::fmt::Display for ChangeDirectory { } impl JoshutoRunnable for ChangeDirectory { - fn execute(&self, context: &mut JoshutoContext) { - Self::change_directory(&self.path, context); + fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + Self::change_directory(&self.path, context, view); preview::preview_file( &mut context.tabs[context.curr_tab_index], - &context.views, + &view, &context.config_t, ); ncurses::doupdate(); |