aboutsummaryrefslogtreecommitdiff
path: root/src/pane.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-04-09 02:20:49 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-04-09 02:20:49 +0300
commit7245aa6c128a475853ac5ffe95c563dcd38bec94 (patch)
tree7cc021c761f617f65d0847e5597bfe1dad76fcf9 /src/pane.rs
parentc62599de008fa898a973138c558fd32732e206de (diff)
fix: only show cursor in focused pane
Diffstat (limited to 'src/pane.rs')
-rw-r--r--src/pane.rs59
1 files changed, 53 insertions, 6 deletions
diff --git a/src/pane.rs b/src/pane.rs
index 3476b387..9552e1c6 100644
--- a/src/pane.rs
+++ b/src/pane.rs
@@ -354,8 +354,8 @@ impl PaneTerminal {
self.ghostty.extract_selection(selection)
}
- fn render(&self, frame: &mut Frame, area: Rect) {
- self.ghostty.render(frame, area);
+ fn render(&self, frame: &mut Frame, area: Rect, show_cursor: bool) {
+ self.ghostty.render(frame, area, show_cursor);
}
fn apply_host_terminal_theme(&self, theme: crate::terminal_theme::TerminalTheme) {
@@ -669,7 +669,7 @@ impl GhosttyPaneTerminal {
.and_then(|mut core| ghostty_extract_selection(&mut core, selection).ok())
}
- fn render(&self, frame: &mut Frame, area: Rect) {
+ fn render(&self, frame: &mut Frame, area: Rect, show_cursor: bool) {
let Ok(mut core) = self.core.lock() else {
return;
};
@@ -732,7 +732,7 @@ impl GhosttyPaneTerminal {
}
}
- if render_state.cursor_visible().ok() == Some(true) {
+ if show_cursor && render_state.cursor_visible().ok() == Some(true) {
if let Ok(Some(cursor)) = render_state.cursor_viewport() {
if cursor.x < area.width && cursor.y < area.height {
frame.set_cursor_position((area.x + cursor.x, area.y + cursor.y));
@@ -1722,8 +1722,8 @@ impl PaneRuntime {
self.terminal.extract_selection(selection)
}
- pub fn render(&self, frame: &mut Frame, area: Rect) {
- self.terminal.render(frame, area);
+ pub fn render(&self, frame: &mut Frame, area: Rect, show_cursor: bool) {
+ self.terminal.render(frame, area, show_cursor);
}
pub fn keyboard_protocol(&self) -> crate::input::KeyboardProtocol {
@@ -1843,6 +1843,30 @@ impl PaneRuntime {
}
#[cfg(test)]
+impl PaneRuntime {
+ pub(crate) fn test_with_screen_bytes(cols: u16, rows: u16, bytes: &[u8]) -> Self {
+ let (tx, _rx) = mpsc::channel(4);
+ let (resize_tx, _resize_rx) = mpsc::channel(1);
+ let mut terminal = crate::ghostty::Terminal::new(cols, rows, 0).unwrap();
+ terminal.write(bytes);
+
+ Self {
+ terminal: Arc::new(PaneTerminal {
+ ghostty: GhosttyPaneTerminal::new(terminal, tx.clone()).unwrap(),
+ }),
+ sender: tx,
+ resize_tx,
+ current_size: Cell::new((rows, cols)),
+ child_pid: Arc::new(AtomicU32::new(0)),
+ kitty_keyboard_flags: Arc::new(AtomicU16::new(0)),
+ detect_reset_notify: Arc::new(Notify::new()),
+ pending_release: Arc::new(Mutex::new(None)),
+ detect_handle: tokio::spawn(async {}).abort_handle(),
+ }
+ }
+}
+
+#[cfg(test)]
mod tests {
use super::*;
@@ -1853,6 +1877,29 @@ mod tests {
}
#[test]
+ fn ghostty_render_can_suppress_cursor_position() {
+ let (tx, _rx) = mpsc::channel(4);
+ let mut first_terminal = crate::ghostty::Terminal::new(20, 5, 0).unwrap();
+ first_terminal.write(b"left");
+ let first = GhosttyPaneTerminal::new(first_terminal, tx.clone()).unwrap();
+
+ let mut second_terminal = crate::ghostty::Terminal::new(20, 5, 0).unwrap();
+ second_terminal.write(b"r\r\nb");
+ let second = GhosttyPaneTerminal::new(second_terminal, tx).unwrap();
+
+ let backend = ratatui::backend::TestBackend::new(40, 5);
+ let mut terminal = ratatui::Terminal::new(backend).unwrap();
+ terminal
+ .draw(|frame| {
+ first.render(frame, Rect::new(0, 0, 20, 5), true);
+ second.render(frame, Rect::new(20, 0, 20, 5), false);
+ })
+ .unwrap();
+
+ terminal.backend_mut().assert_cursor_position((4, 0));
+ }
+
+ #[test]
fn ghostty_keyboard_protocol_tracks_live_terminal_flags() {
let (tx, _rx) = mpsc::channel(4);
let mut terminal = crate::ghostty::Terminal::new(80, 24, 0).unwrap();