summaryrefslogtreecommitdiffstats
path: root/src/commands/parent_directory.rs
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2019-02-15 04:43:09 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2019-02-15 05:56:09 -0800
commit29b3922f9efb9f277641a63f8f1719a15cbb8d16 (patch)
treed919ba11fa5c754565c64c43cb1614f7ae4d2546 /src/commands/parent_directory.rs
parent3853eef2d052460982903038daac7abd2b71d12e (diff)
refactor: project layout
Diffstat (limited to 'src/commands/parent_directory.rs')
-rw-r--r--src/commands/parent_directory.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
new file mode 100644
index 0000000..d9066c6
--- /dev/null
+++ b/src/commands/parent_directory.rs
@@ -0,0 +1,81 @@
+extern crate ncurses;
+
+use commands::{JoshutoCommand, JoshutoRunnable};
+use context::JoshutoContext;
+use preview;
+use ui;
+
+#[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) {
+ if context.curr_tab_mut().curr_path.pop() == false {
+ return;
+ }
+
+ match std::env::set_current_dir(&context.curr_tab_ref().curr_path) {
+ Ok(_) => {
+ {
+ let curr_tab = &mut context.tabs[context.curr_tab_index];
+
+ let curr_list = curr_tab.curr_list.take();
+ curr_tab.history.put_back(curr_list);
+ let parent_list = curr_tab.parent_list.take();
+ curr_tab.curr_list = parent_list;
+
+ match curr_tab.curr_path.parent() {
+ Some(parent) => {
+ curr_tab.parent_list = match curr_tab
+ .history
+ .pop_or_create(&parent, &context.config_t.sort_type)
+ {
+ Ok(s) => Some(s),
+ Err(e) => {
+ ui::wprint_err(&context.views.left_win, e.to_string().as_str());
+ None
+ }
+ };
+ }
+ None => {
+ ncurses::werase(context.views.left_win.win);
+ ncurses::wnoutrefresh(context.views.left_win.win);
+ }
+ }
+ curr_tab.refresh(
+ &context.views,
+ &context.config_t,
+ &context.username,
+ &context.hostname,
+ );
+ }
+ preview::preview_file(context);
+ }
+ Err(e) => {
+ ui::wprint_err(&context.views.bot_win, e.to_string().as_str());
+ }
+ };
+ ncurses::doupdate();
+ }
+}
+
+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) {
+ Self::parent_directory(context);
+ }
+}