summaryrefslogtreecommitdiffstats
path: root/src/commands/parent_directory.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-09-19 21:21:33 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-09-19 21:21:33 -0400
commit7b4c611ed4d804bd52aeda0a619a54bea9b1e13d (patch)
tree7ba31fff7d5de171aadfc32c67f81dd64428b3ba /src/commands/parent_directory.rs
parent7741d4d2c8798ad0bb609e97fb3bda86c5318a36 (diff)
Change command to use an enum instead of polymorphism
Diffstat (limited to 'src/commands/parent_directory.rs')
-rw-r--r--src/commands/parent_directory.rs42
1 files changed, 10 insertions, 32 deletions
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
index 72d629c..0b3eb67 100644
--- a/src/commands/parent_directory.rs
+++ b/src/commands/parent_directory.rs
@@ -1,40 +1,18 @@
-use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
-use crate::ui::TuiBackend;
-#[derive(Clone, Debug)]
-pub struct ParentDirectory;
+use super::reload;
-impl ParentDirectory {
- pub fn new() -> Self {
- ParentDirectory
- }
- pub const fn command() -> &'static str {
- "parent_directory"
- }
-
- pub fn parent_directory(context: &mut JoshutoContext) -> std::io::Result<()> {
- if context.tab_context_mut().curr_tab_mut().pwd_mut().pop() {
- let path = context.tab_context_ref().curr_tab_ref().pwd();
- std::env::set_current_dir(path)?;
- }
- Ok(())
- }
-}
-
-impl JoshutoCommand for ParentDirectory {}
-
-impl std::fmt::Display for ParentDirectory {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- f.write_str(Self::command())
+pub fn parent_directory_helper(context: &mut JoshutoContext) -> std::io::Result<()> {
+ if context.tab_context_mut().curr_tab_mut().pwd_mut().pop() {
+ let path = context.tab_context_ref().curr_tab_ref().pwd();
+ std::env::set_current_dir(path)?;
}
+ Ok(())
}
-impl JoshutoRunnable for ParentDirectory {
- fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
- Self::parent_directory(context)?;
- ReloadDirList::soft_reload(context.tab_context_ref().get_index(), context)?;
- Ok(())
- }
+pub fn parent_directory(context: &mut JoshutoContext) -> JoshutoResult<()> {
+ parent_directory_helper(context)?;
+ reload::soft_reload(context.tab_context_ref().get_index(), context)?;
+ Ok(())
}