blob: d6d05bdd78389124800422d66aaf32303cf0b435 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::ui::TuiBackend;
#[derive(Clone, Debug)]
pub struct ParentDirectory;
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<()> {
let curr_tab = &mut context.tabs[context.curr_tab_index];
if !curr_tab.curr_path.pop() {
return Ok(());
}
std::env::set_current_dir(&curr_tab.curr_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())
}
}
impl JoshutoRunnable for ParentDirectory {
fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
Self::parent_directory(context)?;
ReloadDirList::soft_reload(context.curr_tab_index, context)?;
Ok(())
}
}
|