diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-03 21:50:34 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-03 21:50:34 +0300 |
| commit | 6ea68f9af2569ea87b7d243c5bbe4f3bc4c8fa44 (patch) | |
| tree | de4e52eadb105103ddb71bca87e19de377d64eed /src/server | |
| parent | 045f506ec8a333cde84718304a7d21bcdb93a1fc (diff) | |
fix: forward page keys to primary-screen pagers
refs #953
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/headless.rs | 181 |
1 files changed, 82 insertions, 99 deletions
diff --git a/src/server/headless.rs b/src/server/headless.rs index d0c90f6c..9ef8d1e3 100644 --- a/src/server/headless.rs +++ b/src/server/headless.rs @@ -247,9 +247,9 @@ fn apply_terminal_attach_scroll( AttachScrollDirection::Down => MouseEventKind::ScrollDown, }; if let AttachScrollSource::PageKey { input } = source { - let host_scroll = runtime.input_state().is_some_and(|input_state| { - !input_state.alternate_screen && !input_state.mouse_reporting_enabled() - }); + let host_scroll = runtime + .input_state() + .is_some_and(crate::pane::InputState::plain_page_keys_use_host_scrollback); if host_scroll { match direction { AttachScrollDirection::Up => runtime.scroll_up(lines.max(1) as usize), @@ -5275,14 +5275,17 @@ next_tab = "" rt.shutdown_timeout(Duration::from_millis(100)); } - #[test] - fn terminal_attach_page_key_host_scrolls_plain_terminal() { + fn with_terminal_attach_page_key_runtime( + initial_bytes: &[u8], + initial_scroll: usize, + test: impl FnOnce(&crate::terminal::TerminalRuntime, &mut mpsc::Receiver<Bytes>), + ) { let rt = tokio::runtime::Builder::new_current_thread() .enable_all() .build() .expect("test runtime"); let _runtime_guard = rt.enter(); - let mut bytes = Vec::new(); + let mut bytes = initial_bytes.to_vec(); for line in 0..80 { bytes.extend_from_slice(format!("line {line:02}\r\n").as_bytes()); } @@ -5290,52 +5293,20 @@ next_tab = "" crate::terminal::TerminalRuntime::test_with_channel_and_scrollback_bytes( 20, 5, 4096, &bytes, 4, ); + if initial_scroll > 0 { + runtime.scroll_up(initial_scroll); + } - apply_terminal_attach_scroll( - &runtime, - AttachScrollSource::PageKey { - input: b"\x1b[5~".to_vec(), - }, - AttachScrollDirection::Up, - 4, - None, - None, - 0, - ) - .expect("page key scroll"); + test(&runtime, &mut input_rx); - assert_eq!( - runtime - .scroll_metrics() - .expect("scroll metrics") - .offset_from_bottom, - 4 - ); - assert!(input_rx.try_recv().is_err()); drop(runtime); drop(_runtime_guard); rt.shutdown_timeout(Duration::from_millis(100)); } - #[test] - fn terminal_attach_page_key_forwards_when_mouse_reporting() { - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .expect("test runtime"); - let _runtime_guard = rt.enter(); - let mut bytes = b"\x1b[?1000h".to_vec(); - for line in 0..80 { - bytes.extend_from_slice(format!("line {line:02}\r\n").as_bytes()); - } - let (runtime, mut input_rx) = - crate::terminal::TerminalRuntime::test_with_channel_and_scrollback_bytes( - 20, 5, 4096, &bytes, 4, - ); - runtime.scroll_up(3); - + fn apply_terminal_attach_page_up(runtime: &crate::terminal::TerminalRuntime) { apply_terminal_attach_scroll( - &runtime, + runtime, AttachScrollSource::PageKey { input: b"\x1b[5~".to_vec(), }, @@ -5345,68 +5316,80 @@ next_tab = "" None, 0, ) - .expect("page key forward"); + .expect("page key"); + } - assert_eq!( - runtime - .scroll_metrics() - .expect("scroll metrics") - .offset_from_bottom, - 0 - ); - assert_eq!( - input_rx.try_recv().expect("forwarded page key"), - Bytes::from_static(b"\x1b[5~") - ); - drop(runtime); - drop(_runtime_guard); - rt.shutdown_timeout(Duration::from_millis(100)); + #[test] + fn terminal_attach_page_key_host_scrolls_plain_terminal() { + with_terminal_attach_page_key_runtime(b"", 0, |runtime, input_rx| { + apply_terminal_attach_page_up(runtime); + + assert_eq!( + runtime + .scroll_metrics() + .expect("scroll metrics") + .offset_from_bottom, + 4 + ); + assert!(input_rx.try_recv().is_err()); + }); } #[test] - fn terminal_attach_page_key_forwards_in_alternate_screen_without_mouse_reporting() { - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .expect("test runtime"); - let _runtime_guard = rt.enter(); - let mut bytes = b"\x1b[?1049h".to_vec(); - for line in 0..80 { - bytes.extend_from_slice(format!("line {line:02}\r\n").as_bytes()); - } - let (runtime, mut input_rx) = - crate::terminal::TerminalRuntime::test_with_channel_and_scrollback_bytes( - 20, 5, 4096, &bytes, 4, + fn terminal_attach_page_key_forwards_when_mouse_reporting() { + with_terminal_attach_page_key_runtime(b"\x1b[?1000h", 3, |runtime, input_rx| { + apply_terminal_attach_page_up(runtime); + + assert_eq!( + runtime + .scroll_metrics() + .expect("scroll metrics") + .offset_from_bottom, + 0 ); - runtime.scroll_up(3); + assert_eq!( + input_rx.try_recv().expect("forwarded page key"), + Bytes::from_static(b"\x1b[5~") + ); + }); + } - apply_terminal_attach_scroll( - &runtime, - AttachScrollSource::PageKey { - input: b"\x1b[5~".to_vec(), - }, - AttachScrollDirection::Up, - 4, - None, - None, - 0, - ) - .expect("page key forward"); + #[test] + fn terminal_attach_page_key_forwards_when_application_cursor() { + with_terminal_attach_page_key_runtime(b"\x1b[?1h", 3, |runtime, input_rx| { + apply_terminal_attach_page_up(runtime); - assert_eq!( - runtime - .scroll_metrics() - .expect("scroll metrics") - .offset_from_bottom, - 0 - ); - assert_eq!( - input_rx.try_recv().expect("forwarded page key"), - Bytes::from_static(b"\x1b[5~") - ); - drop(runtime); - drop(_runtime_guard); - rt.shutdown_timeout(Duration::from_millis(100)); + assert_eq!( + runtime + .scroll_metrics() + .expect("scroll metrics") + .offset_from_bottom, + 0 + ); + assert_eq!( + input_rx.try_recv().expect("forwarded page key"), + Bytes::from_static(b"\x1b[5~") + ); + }); + } + + #[test] + fn terminal_attach_page_key_forwards_in_alternate_screen_without_mouse_reporting() { + with_terminal_attach_page_key_runtime(b"\x1b[?1049h", 3, |runtime, input_rx| { + apply_terminal_attach_page_up(runtime); + + assert_eq!( + runtime + .scroll_metrics() + .expect("scroll metrics") + .offset_from_bottom, + 0 + ); + assert_eq!( + input_rx.try_recv().expect("forwarded page key"), + Bytes::from_static(b"\x1b[5~") + ); + }); } #[test] |
