From 5f9a24a2d43307ba4150e1e9357b71ab2f5f2647 Mon Sep 17 00:00:00 2001 From: Rapha Amorim Date: Wed, 19 Feb 2025 00:21:36 -0300 Subject: [PATCH] feat: shell integration - current path (#970) --- corcovado/src/sys/windows/from_raw_arc.rs | 2 +- frontends/rioterm/src/context/title.rs | 26 +++++++++++++++++++ rio-backend/src/crosswords/mod.rs | 2 +- .../src/platform_impl/windows/event_loop.rs | 3 +-- teletypewriter/src/windows/child.rs | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/corcovado/src/sys/windows/from_raw_arc.rs b/corcovado/src/sys/windows/from_raw_arc.rs index 97c15f65..0b46d325 100644 --- a/corcovado/src/sys/windows/from_raw_arc.rs +++ b/corcovado/src/sys/windows/from_raw_arc.rs @@ -108,7 +108,7 @@ mod tests { #[test] fn drops() { struct A<'a>(&'a mut bool); - impl<'a> Drop for A<'a> { + impl Drop for A<'_> { fn drop(&mut self) { *self.0 = true; } diff --git a/frontends/rioterm/src/context/title.rs b/frontends/rioterm/src/context/title.rs index bd61b57f..5e271504 100644 --- a/frontends/rioterm/src/context/title.rs +++ b/frontends/rioterm/src/context/title.rs @@ -154,6 +154,20 @@ pub fn update_title( } } "absolute_path" => { + { + let terminal = context.terminal.lock(); + if let Some(current_directory) = &terminal.current_directory { + if let Ok(dir_str) = + current_directory.clone().into_os_string().into_string() + { + new_template = + new_template.replace(to_replace_str, &dir_str); + matched = true; + continue; + } + }; + } + #[cfg(unix)] { let path = teletypewriter::foreground_process_path( @@ -323,5 +337,17 @@ pub mod test { update_title("{{ absolute_path || title }}", &context), String::from("Something") ); + + // let's modify current_directory to actually be something + { + let path = std::path::PathBuf::from("/tmp"); + let mut term = context.terminal.lock(); + term.current_directory = Some(path); + }; + + assert_eq!( + update_title("{{ absolute_path || title }}", &context), + String::from("/tmp"), + ); } } diff --git a/rio-backend/src/crosswords/mod.rs b/rio-backend/src/crosswords/mod.rs index d697acb1..e3a21bef 100644 --- a/rio-backend/src/crosswords/mod.rs +++ b/rio-backend/src/crosswords/mod.rs @@ -402,7 +402,7 @@ where pub window_id: WindowId, pub route_id: usize, title_stack: Vec, - current_directory: Option, + pub current_directory: Option, hyperlink_re: regex::Regex, // The stack for the keyboard modes. diff --git a/rio-window/src/platform_impl/windows/event_loop.rs b/rio-window/src/platform_impl/windows/event_loop.rs index 60d06620..c830a316 100644 --- a/rio-window/src/platform_impl/windows/event_loop.rs +++ b/rio-window/src/platform_impl/windows/event_loop.rs @@ -597,8 +597,7 @@ impl OwnedDisplayHandle { fn main_thread_id() -> u32 { static mut MAIN_THREAD_ID: u32 = 0; - /// Function pointer used in CRT initialization section to set the above static field's value. - + // Function pointer used in CRT initialization section to set the above static field's value. // Mark as used so this is not removable. #[used] #[allow(non_upper_case_globals)] diff --git a/teletypewriter/src/windows/child.rs b/teletypewriter/src/windows/child.rs index 333eb5d0..9efa3d9f 100644 --- a/teletypewriter/src/windows/child.rs +++ b/teletypewriter/src/windows/child.rs @@ -57,7 +57,7 @@ impl ChildExitWatcher { } else { let pid = unsafe { NonZeroU32::new(GetProcessId(child_handle)) }; Ok(ChildExitWatcher { - wait_handle: AtomicPtr::from(wait_handle as *mut c_void), + wait_handle: AtomicPtr::from(wait_handle), event_rx, child_handle, pid, -- 2.51.2