diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs index b2af8cb8ee..74eb553909 100644 --- a/codex-rs/tui/src/app.rs +++ b/codex-rs/tui/src/app.rs @@ -899,6 +899,12 @@ impl App { app_server: &mut AppServerSession, event: TuiEvent, ) -> Result { + if matches!(event, TuiEvent::Draw) && tui::tmux_mouse_disabled() { + self.sidebar_press = None; + self.divider_drag = None; + self.chat_widget.end_composer_drag(); + self.chat_widget.rendered_selection.borrow_mut().end_drag(); + } match &event { TuiEvent::Draw | TuiEvent::Mouse(crossterm::event::MouseEvent { diff --git a/codex-rs/tui/src/app/link_hover.rs b/codex-rs/tui/src/app/link_hover.rs index 587eaeb0aa..884e4b1556 100644 --- a/codex-rs/tui/src/app/link_hover.rs +++ b/codex-rs/tui/src/app/link_hover.rs @@ -187,7 +187,7 @@ impl App { let Some((id, area)) = self.passive_link_drag else { return Ok(false); }; - if self.conversation_focus_available(tui) { + if self.conversation_focus_available(tui) && !crate::tui::tmux_mouse_disabled() { match event { TuiEvent::Draw => { if let Some(companion) = self.side_companions.get_mut(&id) diff --git a/codex-rs/tui/src/footer_selection_tests.rs b/codex-rs/tui/src/footer_selection_tests.rs index 05c8187c76..98c5040e28 100644 --- a/codex-rs/tui/src/footer_selection_tests.rs +++ b/codex-rs/tui/src/footer_selection_tests.rs @@ -154,15 +154,24 @@ fn stationary_clicks_are_deferred_but_dragging_back_does_not_activate() { selection.handle_event(&mouse(Up(Left), /*column*/ 5, /*row*/ 0), &buffer), Some(RegionAction::Click(_)) )); - // A stationary click after a selection releases the frozen revision. - for event in [ - mouse(Down(Left), /*column*/ 0, /*row*/ 0), - mouse(Drag(Left), /*column*/ 3, /*row*/ 0), - mouse(Up(Left), /*column*/ 3, /*row*/ 0), - ] { - selection.handle_event(&event, &buffer); - } + // Losing capture cancels a deferred click, even if its release arrives late. + selection.handle_event(&mouse(Down(Left), /*column*/ 8, /*row*/ 0), &buffer); + selection.end_drag(); + assert!( + selection + .handle_event(&mouse(Up(Left), /*column*/ 8, /*row*/ 0), &buffer) + .is_none() + ); + + selection.handle_event(&mouse(Down(Left), /*column*/ 0, /*row*/ 0), &buffer); + selection.handle_event(&mouse(Drag(Left), /*column*/ 3, /*row*/ 0), &buffer); assert!(selection.view.has_selection_range()); + let selected = selection.view.selected_text(&selection.cells); + selection.end_drag(); + selection.handle_event(&mouse(Up(Left), /*column*/ 9, /*row*/ 0), &buffer); + assert_eq!(selection.view.selected_text(&selection.cells), selected); + + // A stationary click after a selection releases the frozen revision. selection.handle_event(&mouse(Down(Left), /*column*/ 10, /*row*/ 0), &buffer); assert!(matches!( selection.handle_event(&mouse(Up(Left), /*column*/ 10, /*row*/ 0), &buffer), diff --git a/codex-rs/tui/src/rendered_selection.rs b/codex-rs/tui/src/rendered_selection.rs index 386456176a..bd7b1ef333 100644 --- a/codex-rs/tui/src/rendered_selection.rs +++ b/codex-rs/tui/src/rendered_selection.rs @@ -39,6 +39,11 @@ pub(crate) enum RegionAction { } impl RenderedSelection { + pub(crate) fn end_drag(&mut self) { + self.pressed = None; + self.view.end_drag(); + } + pub(crate) fn clear(&mut self) { self.view.jump_to_latest(); self.snapshot = None; diff --git a/codex-rs/tui/src/transcript_view/selection.rs b/codex-rs/tui/src/transcript_view/selection.rs index 859aeacb11..f1ba0237a9 100644 --- a/codex-rs/tui/src/transcript_view/selection.rs +++ b/codex-rs/tui/src/transcript_view/selection.rs @@ -857,6 +857,11 @@ impl TranscriptView { } pub(crate) fn tick_selection(&mut self, cells: &[Arc]) -> bool { + // A lost release can strand a Back to bottom press even without a text selection. + if crate::tui::tmux_mouse_disabled() { + self.end_drag(); + return false; + } let snapshot = self.snapshot_cells(); let cells = snapshot.as_deref().unwrap_or(cells); let Some(selection) = self diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index ecc93593f0..40b0ca55b6 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -127,6 +127,11 @@ pub(crate) fn reports_key_releases() -> bool { keyboard_modes::reports_key_releases() } +pub(crate) fn tmux_mouse_disabled() -> bool { + ALTERNATE_SCREEN.is_active() + && ALTERNATE_SCREEN.tmux_mouse() == tmux::MouseCapture::DisabledByTmux +} + fn should_emit_notification(condition: NotificationCondition, terminal_focused: bool) -> bool { match condition { NotificationCondition::Unfocused => !terminal_focused, @@ -933,6 +938,28 @@ impl Tui { } } + // Nested screens such as /resume retain the capture request across draws. + // Apply a new tmux policy even if the screen never changes its request. + fn refresh_tmux_mouse(&mut self) -> Result<()> { + if ALTERNATE_SCREEN.is_active() + && let Some(mouse) = self + .event_broker + .size_monitor + .as_ref() + .and_then(size_monitor::SizeMonitor::mouse) + { + // Selection ticks can run before this draw applies the policy. Give + // even a stationary drag a chance to end without a button release. + if mouse == tmux::MouseCapture::DisabledByTmux && mouse != ALTERNATE_SCREEN.tmux_mouse() + { + self.frame_requester.schedule_frame(); + } + ALTERNATE_SCREEN.set_tmux_mouse(mouse); + self.set_mouse_capture(self.mouse_capture)?; + } + Ok(()) + } + pub fn set_notification_settings( &mut self, method: NotificationMethod, @@ -1213,6 +1240,9 @@ impl Tui { self.terminal.backend_mut(), self.mouse_capture.captures_mouse(self.owned_screen), ); + if let Some(monitor) = &self.event_broker.size_monitor { + monitor.reset_mouse(); + } self.alt_screen_active .store(ALTERNATE_SCREEN.is_active(), Ordering::Relaxed); if !self.is_alt_screen_active() { @@ -1472,6 +1502,7 @@ impl Tui { height: u16, draw_fn: impl FnOnce(&mut custom_terminal::Frame), ) -> Result<()> { + self.refresh_tmux_mouse()?; let screen_size = self.take_event_screen_size()?; // If we are resuming from ^Z, we need to prepare the resume action now so we can apply it // in the synchronized update. @@ -1633,6 +1664,7 @@ impl Tui { hud: Option, draw_fn: impl FnOnce(&mut custom_terminal::Frame), ) -> Result<()> { + self.refresh_tmux_mouse()?; // This draw uses the caller's resolved geometry directly, so its reservation is consumed. self.screen_size.pending_draw_size = None; // If we are resuming from ^Z, we need to prepare the resume action now so we can apply it diff --git a/codex-rs/tui/src/tui/alternate_screen.rs b/codex-rs/tui/src/tui/alternate_screen.rs index 3052820844..bb650c4c25 100644 --- a/codex-rs/tui/src/tui/alternate_screen.rs +++ b/codex-rs/tui/src/tui/alternate_screen.rs @@ -3,7 +3,7 @@ //! Push only on entry and pop before leaving or yielding input to an editor. The main screen //! keeps its own TUI mode until the handoff returns to it. Transcript surfaces retain pointer //! reporting across overlays and disable it before yielding. Promoting an overlay must not push -//! another keyboard frame. Refresh tmux's input policy on entry for mouse-capture requests. +//! another keyboard frame. A live tmux mouse change only reconfigures pointer input. use std::io::Result; use std::io::Write; @@ -44,7 +44,7 @@ pub(super) struct AlternateScreen { link_pointer: super::link_pointer::LinkPointer, active: AtomicBool, mouse_active: AtomicBool, - // Refresh alongside keyboard modes whenever this screen is entered or restored. + // Seed on screen entry and refresh independently of the keyboard stack. mouse_capture_disabled: AtomicBool, // A cleanup/setup error must not make the next identical request look already applied. input_configured: AtomicBool, @@ -105,13 +105,29 @@ impl AlternateScreen { !cfg!(windows) && !keyboard_modes::keyboard_enhancement_disabled(), Ordering::Relaxed, ); - self.mouse_capture_disabled.store( - mouse_capture == tmux::MouseCapture::DisabledByTmux, - Ordering::Relaxed, - ); + self.set_tmux_mouse(mouse_capture); self.configure_input(writer, capture_mouse) } + pub(super) fn tmux_mouse(&self) -> tmux::MouseCapture { + if self.mouse_capture_disabled.load(Ordering::Relaxed) { + tmux::MouseCapture::DisabledByTmux + } else { + tmux::MouseCapture::Enabled + } + } + + pub(super) fn set_tmux_mouse(&self, mouse: tmux::MouseCapture) { + if self.tmux_mouse() != mouse { + self.mouse_capture_disabled.store( + mouse == tmux::MouseCapture::DisabledByTmux, + Ordering::Relaxed, + ); + self.input_configured + .store(/*val*/ false, Ordering::Relaxed); + } + } + pub(super) fn configure_input( &self, writer: &mut impl Write, diff --git a/codex-rs/tui/src/tui/alternate_screen_tests.rs b/codex-rs/tui/src/tui/alternate_screen_tests.rs index 6ae211ba42..a176ad161a 100644 --- a/codex-rs/tui/src/tui/alternate_screen_tests.rs +++ b/codex-rs/tui/src/tui/alternate_screen_tests.rs @@ -28,15 +28,17 @@ fn refreshed_mouse_policy_applies_to_fullscreen_and_overlays() { screen .enter(&mut output, input.captures_mouse(owned)) .unwrap(); - for disabled in [true, false, true] { - screen - .mouse_capture_disabled - .store(disabled, Ordering::Relaxed); - for next in [ - MouseCapture::Enabled, - MouseCapture::Inherit, - MouseCapture::Disabled, + for next in [ + MouseCapture::Inherit, + MouseCapture::Enabled, + MouseCapture::Disabled, + ] { + for mouse in [ + tmux::MouseCapture::Enabled, + tmux::MouseCapture::DisabledByTmux, + tmux::MouseCapture::Enabled, ] { + screen.set_tmux_mouse(mouse); input.apply(&screen, &mut output, next, owned).unwrap(); terminal.process(&std::mem::take(&mut output)); let capture = match next { @@ -44,7 +46,7 @@ fn refreshed_mouse_policy_applies_to_fullscreen_and_overlays() { MouseCapture::Enabled => true, MouseCapture::Disabled => false, }; - let expected = if !disabled && capture { + let expected = if mouse == tmux::MouseCapture::Enabled && capture { vt100::MouseProtocolMode::AnyMotion } else { vt100::MouseProtocolMode::None diff --git a/codex-rs/tui/src/tui/event_stream.rs b/codex-rs/tui/src/tui/event_stream.rs index 348b03a81a..c28aac89b8 100644 --- a/codex-rs/tui/src/tui/event_stream.rs +++ b/codex-rs/tui/src/tui/event_stream.rs @@ -346,6 +346,8 @@ impl TuiEventStream { self.terminal_focused.store(false, Ordering::Relaxed); Some(TuiEvent::FocusLost) } + // A report queued before capture stopped can precede the cleanup draw. + Event::Mouse(_) if super::tmux_mouse_disabled() => None, Event::Mouse(mouse) => Some(TuiEvent::Mouse(mouse)), } } diff --git a/codex-rs/tui/src/tui/size_monitor.rs b/codex-rs/tui/src/tui/size_monitor.rs index cf50fd8e3b..55a01c568f 100644 --- a/codex-rs/tui/src/tui/size_monitor.rs +++ b/codex-rs/tui/src/tui/size_monitor.rs @@ -1,4 +1,4 @@ -//! Recovers lost tmux resize notifications without querying geometry on the UI thread. +//! Recovers missed tmux resizes and mouse setting changes off the UI thread. //! //! One worker belongs to the event broker, including across nested screens. Queries never //! hold the shared lock. Pauses and newer geometry invalidate both in-flight and queued @@ -10,6 +10,10 @@ use std::sync::Arc; use std::sync::Mutex; use std::thread; use std::time::Duration; +use std::time::Instant; + +use super::alternate_screen::ALTERNATE_SCREEN; +use super::tmux; use codex_terminal_detection::Multiplexer; use codex_terminal_detection::TerminalInfo; @@ -17,11 +21,15 @@ use ratatui::layout::Size; use tokio::sync::broadcast; const CHECK_INTERVAL: Duration = Duration::from_millis(500); +// tmux does not notify the pane when "set mouse" changes. Unlike the geometry +// ioctl, this check starts a subprocess, so sample less often and only in fullscreen. +const MOUSE_CHECK_INTERVAL: Duration = Duration::from_secs(2); struct State { size: Size, generation: u64, pending: Option, + mouse: Option, active: bool, stopped: bool, } @@ -40,9 +48,20 @@ impl SizeMonitor { if !cfg!(unix) || !matches!(terminal_info.multiplexer, Some(Multiplexer::Tmux { .. })) { return None; } - Self::spawn(size, draw_tx, || { + let mut last_mouse_check = Instant::now(); + Self::spawn(size, draw_tx, move |previous_mouse| { + let mouse = if ALTERNATE_SCREEN.is_active() + && last_mouse_check.elapsed() >= MOUSE_CHECK_INTERVAL + { + last_mouse_check = Instant::now(); + tmux::sample_mouse(previous_mouse.unwrap_or_else(|| ALTERNATE_SCREEN.tmux_mouse())) + } else { + None + }; // Unlike terminal::size(), window_size() has no tput subprocess fallback. - crossterm::terminal::window_size().map(|size| Size::new(size.columns, size.rows)) + let size = + crossterm::terminal::window_size().map(|size| Size::new(size.columns, size.rows)); + (size, mouse) }) .inspect_err(|error| tracing::warn!(%error, "Failed to start terminal size monitor")) .ok() @@ -51,12 +70,17 @@ impl SizeMonitor { fn spawn( size: Size, draw_tx: broadcast::Sender<()>, - mut query: impl FnMut() -> io::Result + Send + 'static, + mut query: impl FnMut( + Option, + ) -> (io::Result, Option) + + Send + + 'static, ) -> io::Result { let state = Arc::new(Mutex::new(State { size, generation: 0, pending: None, + mouse: None, active: true, stopped: false, })); @@ -66,7 +90,7 @@ impl SizeMonitor { .spawn(move || { loop { thread::park_timeout(CHECK_INTERVAL); - let generation = { + let (generation, previous_mouse) = { let state = shared .lock() .unwrap_or_else(std::sync::PoisonError::into_inner); @@ -76,9 +100,9 @@ impl SizeMonitor { if !state.active { continue; } - state.generation + (state.generation, state.mouse) }; - let sampled = query(); + let (sampled, mouse) = query(previous_mouse); let mut state = shared .lock() .unwrap_or_else(std::sync::PoisonError::into_inner); @@ -91,7 +115,11 @@ impl SizeMonitor { state.pending = sampled .ok() .filter(|size| size.width > 0 && size.height > 0 && *size != state.size); - if state.pending.is_some() { + let mouse_changed = mouse.is_some() && mouse != state.mouse; + if mouse_changed { + state.mouse = mouse; + } + if state.pending.is_some() || mouse_changed { drop(state); let _ = draw_tx.send(()); } @@ -118,6 +146,25 @@ impl SizeMonitor { state.active = active; state.generation = state.generation.wrapping_add(1); state.pending = None; + state.mouse = None; + } + + // Screen entry probes tmux synchronously. Discard older samples, including + // any query still in flight when that probe finished. + pub(super) fn reset_mouse(&self) { + let mut state = self + .state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + state.generation = state.generation.wrapping_add(1); + state.mouse = None; + } + + pub(super) fn mouse(&self) -> Option { + self.state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .mouse } pub(super) fn take_resize(&self) -> Option { diff --git a/codex-rs/tui/src/tui/size_monitor_tests.rs b/codex-rs/tui/src/tui/size_monitor_tests.rs index 957b055008..9e8a73d66d 100644 --- a/codex-rs/tui/src/tui/size_monitor_tests.rs +++ b/codex-rs/tui/src/tui/size_monitor_tests.rs @@ -47,7 +47,7 @@ impl EventSource for KeySource { struct Harness { broker: Arc>, queries: tokio::sync::mpsc::UnboundedReceiver<()>, - replies: std::sync::mpsc::Sender>, + replies: std::sync::mpsc::Sender<(io::Result, Option)>, draws: broadcast::Receiver<()>, } @@ -56,11 +56,11 @@ impl Harness { let (draw_tx, draws) = broadcast::channel(/*capacity*/ 1); let (started, queries) = tokio::sync::mpsc::unbounded_channel(); let (replies, responses) = std::sync::mpsc::channel(); - let monitor = SizeMonitor::spawn(size, draw_tx, move || { + let monitor = SizeMonitor::spawn(size, draw_tx, move |_| { let _ = started.send(()); responses .recv_timeout(Duration::from_secs(5)) - .unwrap_or_else(|_| Err(io::Error::other("test query was not released"))) + .unwrap_or_else(|_| (Err(io::Error::other("test query was not released")), None)) }) .expect("monitor"); let mut broker = EventBroker::new(); @@ -123,7 +123,7 @@ async fn missed_resize_recovers_and_slow_query_does_not_block_input() { .await .is_err() ); - harness.replies.send(Ok(resized)).unwrap(); + harness.replies.send((Ok(resized), None)).unwrap(); let event = timeout(Duration::from_secs(2), stream.next()) .await .unwrap() @@ -158,7 +158,7 @@ async fn newer_resize_invalidates_in_flight_and_queued_samples() { let mut harness = Harness::new(initial); harness.next_query().await; harness.monitor().observe(newer); - harness.replies.send(Ok(initial)).unwrap(); + harness.replies.send((Ok(initial), None)).unwrap(); harness.next_query().await; // The previous result has been processed. assert_eq!(harness.monitor().take_resize(), None); assert_eq!( @@ -166,7 +166,7 @@ async fn newer_resize_invalidates_in_flight_and_queued_samples() { Err(broadcast::error::TryRecvError::Empty) ); - harness.replies.send(Ok(initial)).unwrap(); + harness.replies.send((Ok(initial), None)).unwrap(); timeout(Duration::from_secs(2), harness.draws.recv()) .await .unwrap() @@ -185,7 +185,7 @@ async fn unchanged_invalid_and_failed_samples_do_not_redraw() { Ok(Size::new(/*width*/ 0, /*height*/ 0)), Err(io::Error::other("query failed")), ] { - harness.replies.send(sample).unwrap(); + harness.replies.send((sample, None)).unwrap(); harness.next_query().await; assert_eq!(harness.monitor().take_resize(), None); assert_eq!( @@ -195,6 +195,34 @@ async fn unchanged_invalid_and_failed_samples_do_not_redraw() { } } +#[tokio::test] +async fn mouse_change_wakes_idle_screen_and_ignores_stale_or_failed_probes() { + let size = Size::new(/*width*/ 80, /*height*/ 24); + let mut harness = Harness::new(size); + let off = Some(tmux::MouseCapture::DisabledByTmux); + let on = Some(tmux::MouseCapture::Enabled); + harness.next_query().await; + for (sample, expected, redraw) in [ + (off, off, true), + (None, off, false), + (on, on, true), + (on, on, false), + ] { + harness.replies.send((Ok(size), sample)).unwrap(); + harness.next_query().await; + assert_eq!( + (harness.monitor().mouse(), harness.draws.try_recv().is_ok()), + (expected, redraw) + ); + } + + // A new screen entry has already read a newer policy. + harness.monitor().reset_mouse(); + harness.replies.send((Ok(size), off)).unwrap(); + harness.next_query().await; + assert_eq!(harness.monitor().mouse(), None); +} + #[tokio::test] async fn terminal_handoff_pauses_queries_and_discards_old_results() { let initial = Size::new(/*width*/ 80, /*height*/ 24); @@ -202,7 +230,7 @@ async fn terminal_handoff_pauses_queries_and_discards_old_results() { let mut harness = Harness::new(initial); harness.next_query().await; harness.broker.pause_events(); - harness.replies.send(Ok(resized)).unwrap(); + harness.replies.send((Ok(resized), None)).unwrap(); harness.monitor().worker.thread().unpark(); assert!( timeout(Duration::from_millis(100), harness.queries.recv()) @@ -212,7 +240,7 @@ async fn terminal_handoff_pauses_queries_and_discards_old_results() { assert_eq!(harness.monitor().take_resize(), None); harness.broker.resume_events(); harness.next_query().await; - harness.replies.send(Ok(resized)).unwrap(); + harness.replies.send((Ok(resized), None)).unwrap(); timeout(Duration::from_secs(2), harness.draws.recv()) .await .unwrap() @@ -230,7 +258,7 @@ async fn drop_does_not_wait_for_a_blocked_query_or_start_another() { assert!(state.lock().unwrap().stopped); harness .replies - .send(Ok(Size::new(/*width*/ 40, /*height*/ 12))) + .send((Ok(Size::new(/*width*/ 40, /*height*/ 12)), None)) .unwrap(); assert_eq!( timeout(Duration::from_secs(2), harness.queries.recv()) diff --git a/codex-rs/tui/src/tui/tmux.rs b/codex-rs/tui/src/tui/tmux.rs index d24b7583f9..b63e086106 100644 --- a/codex-rs/tui/src/tui/tmux.rs +++ b/codex-rs/tui/src/tui/tmux.rs @@ -26,6 +26,69 @@ pub(super) enum MouseCapture { DisabledByTmux, } +impl MouseCapture { + fn parse(mouse: &str) -> Option { + match mouse.trim() { + "0" | "off" => Some(Self::DisabledByTmux), + "1" | "on" => Some(Self::Enabled), + _ => None, + } + } +} + +fn command() -> Option { + let executable = codex_utils_path::system_executable("tmux")?; + let path = codex_utils_path::system_path().ok()?; + let mut command = Command::new(executable); + command + .env("PATH", path) + .stdin(Stdio::null()) + .stderr(Stdio::null()); + Some(command) +} + +// Without a pane ID or a tty on stdin, tmux defaults to the most recently +// active session. TMUX contains the socket, server PID and containing session ID. +fn target() -> Option { + std::env::var("TMUX_PANE") + .ok() + .filter(|pane| !pane.is_empty()) + .or_else(|| { + let tmux = std::env::var("TMUX").ok()?; + let (session, _pid, _socket) = tmux.rsplitn(3, ',').collect_tuple()?; + let id = session.parse::().ok()?; + Some(format!("${id}:")) + }) +} + +/// A failed refresh must preserve the last confirmed policy, including mouse off. +pub(super) fn sample_mouse(previous: MouseCapture) -> Option { + let target = target()?; + // tmux clears the socket's execute bits when its last client detaches. + // Avoid spawning commands (and filling show-messages) on an idle server. + #[cfg(unix)] + if let Ok(tmux) = std::env::var("TMUX") + && let Some(socket) = tmux.rsplitn(3, ',').nth(2) + { + use std::os::unix::fs::PermissionsExt; + if std::fs::metadata(socket).ok()?.permissions().mode() & 0o111 == 0 { + return None; + } + } + let mut command = command()?; + // if-shell -F evaluates a tmux format without running a shell. Only invoke + // display-message (and the user's after-display-message hook) on a change. + let (condition, report) = match previous { + MouseCapture::Enabled => ("#{==:#{mouse},0}", "display-message -p 0"), + MouseCapture::DisabledByTmux => ("#{==:#{mouse},1}", "display-message -p 1"), + }; + command.args(["if-shell", "-F", "-t", &target, condition, report]); + // Keep the periodic check short so a busy server cannot starve resize recovery. + let deadline = Instant::now() + Duration::from_millis(/*millis*/ 100); + let output = command_stdout_before_deadline(&mut command, deadline)?; + MouseCapture::parse(std::str::from_utf8(&output).ok()?) +} + #[derive(Debug, Default, PartialEq, Eq)] pub(super) struct Options { pub(super) extended_keys_format: Option, @@ -34,16 +97,10 @@ pub(super) struct Options { } pub(super) fn options() -> Options { - let pane = std::env::var("TMUX_PANE").ok(); + let pane = target(); if std::env::var_os("TMUX").is_none() && pane.is_none() { return Options::default(); } - let Some(executable) = codex_utils_path::system_executable("tmux") else { - return Options::default(); - }; - let Ok(path) = codex_utils_path::system_path() else { - return Options::default(); - }; if PROBE_IN_FLIGHT.swap(true, Ordering::AcqRel) { return Options::default(); } @@ -53,13 +110,7 @@ pub(super) fn options() -> Options { .name("tmux-options".into()) .spawn(move || { let options = read_options(pane.as_deref(), |args| { - let mut command = Command::new(&executable); - command - .env("PATH", &path) - .args(args) - .stdin(Stdio::null()) - .stderr(Stdio::null()); - command_stdout_before_deadline(&mut command, deadline) + command_stdout_before_deadline(command()?.args(args), deadline) }); PROBE_IN_FLIGHT.store(false, Ordering::Release); let _ = sender.send(options); @@ -94,9 +145,7 @@ fn read_options(pane: Option<&str>, mut run: impl FnMut(&[&str]) -> Option