From 47f7d51e469e66fc8f7f94acdeb791d895378619 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 1 Jun 2022 22:28:10 +0530 Subject: [PATCH] Cleanups --- src/app.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/app.rs b/src/app.rs index fea5f43..c1952c5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -35,6 +35,14 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const TEMPLATE_TABLE_ROW: &str = "TEMPLATE_TABLE_ROW"; pub const UNSUPPORTED_STR: &str = "???"; +fn set_current_dir(path: &str, hostname: &str) -> std::io::Result<()> { + env::set_current_dir(path).map(|r| { + print!("\x1b]7;file://{}{}\x1b\\", hostname, path); + std::io::stdout().flush().ok(); + r + }) +} + #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub struct Task { pub msg: MsgIn, @@ -283,16 +291,15 @@ impl App { explorer_config.sorters = sorters.clone(); }; - env::set_current_dir(&pwd)?; + let hostname = gethostname().to_string_lossy().to_string(); let pwd = pwd.to_string_lossy().to_string(); + set_current_dir(&pwd, &hostname)?; let input = InputBuffer { buffer: Default::default(), prompt: config.general.prompt.format.clone().unwrap_or_default(), }; - let hostname = gethostname().to_string_lossy().to_string(); - let mut app = Self { version: VERSION.to_string(), config, @@ -749,18 +756,18 @@ impl App { dir = PathBuf::from(self.pwd.clone()).join(dir); } - match env::set_current_dir(&dir) { + let dir = dir.to_string_lossy().to_string(); + + match set_current_dir(&dir, &self.hostname) { Ok(()) => { let pwd = self.pwd.clone(); let focus = self.focused_node().map(|n| n.relative_path.clone()); self = self.add_last_focus(pwd, focus)?; - self.pwd = dir.to_string_lossy().to_string(); + self.pwd = dir; if save_history { self.history = self.history.push(format!("{}/", self.pwd)); } - print!("\x1b]7;file://{}{}\x1b\\", &self.hostname, &self.pwd); - std::io::stdout().flush().ok(); self.explore_pwd() } Err(e) => self.log_error(e.to_string()),