diff options
Diffstat (limited to 'src/commands/change_directory.rs')
-rw-r--r-- | src/commands/change_directory.rs | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index d62964e..48cf901 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -1,10 +1,10 @@ use std::path; -use crate::commands::{JoshutoCommand, JoshutoRunnable}; +use crate::commands::{JoshutoCommand, JoshutoRunnable, LoadChild}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; use crate::history::DirectoryHistory; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; #[derive(Clone, Debug)] pub struct ChangeDirectory { @@ -19,30 +19,27 @@ impl ChangeDirectory { "cd" } - pub fn change_directory( - path: &path::PathBuf, + pub fn cd( + path: &path::Path, context: &mut JoshutoContext, - view: &JoshutoView, ) -> std::io::Result<()> { - std::env::set_current_dir(path.as_path())?; + std::env::set_current_dir(path)?; let curr_tab = &mut context.tabs[context.curr_tab_index]; - let mut curr_list = curr_tab - .history - .pop_or_create(&path, &context.config_t.sort_option)?; + curr_tab.curr_path = path.to_path_buf(); - std::mem::swap(&mut curr_tab.curr_list, &mut curr_list); + Ok(()) + } - curr_tab - .history - .insert(curr_list.file_path().clone(), curr_list); - curr_tab.curr_path = path.clone(); + pub fn change_directories(path: &path::Path, + context: &mut JoshutoContext, + backend: &mut TuiBackend, + ) -> std::io::Result<()> { + Self::cd(path, context)?; - curr_tab - .history - .populate_to_root(path, &context.config_t.sort_option)?; + let curr_tab = &mut context.tabs[context.curr_tab_index]; + curr_tab.history.populate_to_root(&path, &context.config_t.sort_option)?; - curr_tab.refresh(view, &context.config_t); Ok(()) } } @@ -56,9 +53,10 @@ impl std::fmt::Display for ChangeDirectory { } impl JoshutoRunnable for ChangeDirectory { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - Self::change_directory(&self.path, context, view)?; - ncurses::doupdate(); + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + Self::change_directories(&self.path, context, backend)?; + LoadChild::load_child(context, backend); + Ok(()) } } |