diff --git a/packages/nx/src/native/tui/components/terminal_pane.rs b/packages/nx/src/native/tui/components/terminal_pane.rs index 5007082c41..b4b7186ed9 100644 --- a/packages/nx/src/native/tui/components/terminal_pane.rs +++ b/packages/nx/src/native/tui/components/terminal_pane.rs @@ -254,8 +254,8 @@ impl<'a> TerminalPane<'a> { | TaskStatus::RemoteCache => Color::Green, TaskStatus::Failure => Color::Red, TaskStatus::Skipped => Color::Yellow, - TaskStatus::InProgress | TaskStatus::Shared=> Color::LightCyan, - TaskStatus::NotStarted | TaskStatus::Stopped=> Color::DarkGray, + TaskStatus::InProgress | TaskStatus::Shared => Color::LightCyan, + TaskStatus::NotStarted | TaskStatus::Stopped => Color::DarkGray, }) } @@ -420,7 +420,7 @@ impl<'a> StatefulWidget for TerminalPane<'a> { ScrollbarState::default() }; - let pseudo_term = PseudoTerminal::new(&screen).block(block); + let pseudo_term = PseudoTerminal::new(&*screen).block(block); Widget::render(pseudo_term, area, buf); // Only render scrollbar if needed diff --git a/packages/nx/src/native/tui/pty.rs b/packages/nx/src/native/tui/pty.rs index f1a9ab05d5..6f9e6022ee 100644 --- a/packages/nx/src/native/tui/pty.rs +++ b/packages/nx/src/native/tui/pty.rs @@ -6,6 +6,26 @@ use vt100_ctt::Parser; use super::utils::normalize_newlines; +/// A wrapper that provides access to the terminal screen without cloning +/// +/// This struct uses a read lock guard internally to maintain the lock on the parser while +/// allowing access to just the screen through deref coercion. This approach avoids the need to +/// clone the entire screen while still providing safe access to it. The guard is kept private +/// to ensure the lock is held for the lifetime of this reference. +/// +/// Using Deref allows callers to treat this as if it were a direct reference to Screen. +pub struct PtyScreenRef<'a> { + _guard: std::sync::RwLockReadGuard<'a, Parser>, +} + +impl std::ops::Deref for PtyScreenRef<'_> { + type Target = vt100_ctt::Screen; + + fn deref(&self) -> &Self::Target { + self._guard.screen() + } +} + #[derive(Clone)] pub struct PtyInstance { pub task_id: String, @@ -73,8 +93,11 @@ impl PtyInstance { Ok(()) } - pub fn get_screen(&self) -> Option { - self.parser.read().ok().map(|p| p.screen().clone()) + pub fn get_screen(&self) -> Option { + self.parser + .read() + .ok() + .map(|guard| PtyScreenRef { _guard: guard }) } pub fn scroll_up(&mut self) {