From d35a4c58cb95de27a81ff80337528f8a27042163 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Thu, 2 Jun 2022 10:21:15 +0530 Subject: [PATCH] Write OSC 7 escaped codes on a the tui backend --- src/app.rs | 17 +++-------------- src/runner.rs | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/app.rs b/src/app.rs index c1952c5..a40b139 100644 --- a/src/app.rs +++ b/src/app.rs @@ -27,7 +27,6 @@ use std::collections::HashMap; use std::collections::VecDeque; use std::env; use std::fs; -use std::io::Write; use std::path::PathBuf; use tui_input::{Input, InputRequest}; @@ -35,14 +34,6 @@ 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, @@ -293,7 +284,7 @@ impl App { let hostname = gethostname().to_string_lossy().to_string(); let pwd = pwd.to_string_lossy().to_string(); - set_current_dir(&pwd, &hostname)?; + env::set_current_dir(&pwd)?; let input = InputBuffer { buffer: Default::default(), @@ -756,15 +747,13 @@ impl App { dir = PathBuf::from(self.pwd.clone()).join(dir); } - let dir = dir.to_string_lossy().to_string(); - - match set_current_dir(&dir, &self.hostname) { + match env::set_current_dir(&dir) { 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; + self.pwd = dir.to_string_lossy().to_string(); if save_history { self.history = self.history.push(format!("{}/", self.pwd)); } diff --git a/src/runner.rs b/src/runner.rs index 416d86a..e7f66f1 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -358,8 +358,6 @@ impl Runner { Refresh => { // $PWD watcher tx_pwd_watcher.send(app.pwd.clone())?; - // UI - terminal.draw(|f| ui::draw(f, &app, &lua))?; // Fifo let focus = app.focused_node(); if focus != last_focus.as_ref() { @@ -371,7 +369,19 @@ impl Runner { )?; }; last_focus = focus.cloned(); + + // OSC 7: Change CWD + terminal.backend_mut().write( + format!( + "\x1b]7;file://{}{}\x1b\\", + &app.hostname, &app.pwd + ) + .as_bytes(), + )?; } + + // UI + terminal.draw(|f| ui::draw(f, &app, &lua))?; } EnableMouse => {