thing-tui: mouse capture is not a byte sequence on Windows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-29 01:51:15 +01:00
commit 336fb892df

View file

@ -117,19 +117,26 @@ fn print_writes_the_text_in_place() {
assert!(has(&bytes, "\x1b[1;1Hh\u{e9}llo"), "{bytes:?}");
}
const ENTER: [&str; 5] = ["\x1b[?1049h", "\x1b[?25l", "\x1b[?1000h", "\x1b[?1004h", "\x1b[?2004h"];
const RESTORE: [&str; 5] = ["\x1b[?2004l", "\x1b[?1004l", "\x1b[?1000l", "\x1b[?25h", "\x1b[?1049l"];
/// What crossterm writes as bytes. On Windows, mouse capture is a console-mode call, not an escape
/// sequence, so it is not in the stream there.
const MOUSE: bool = cfg!(not(windows));
const ENTER: [(&str, bool); 5] = [("\x1b[?1049h", true), ("\x1b[?25l", true), ("\x1b[?1000h", MOUSE), ("\x1b[?1004h", true), ("\x1b[?2004h", true)];
const RESTORE: [(&str, bool); 5] = [("\x1b[?2004l", true), ("\x1b[?1004l", true), ("\x1b[?1000l", MOUSE), ("\x1b[?25h", true), ("\x1b[?1049l", true)];
fn modes(table: [(&'static str, bool); 5]) -> impl Iterator<Item = &'static str> {
table.into_iter().filter(|(_, bytes)| *bytes).map(|(sequence, _)| sequence)
}
#[test]
fn entering_writes_every_mode_and_restoring_undoes_each() {
let mut entered = Vec::new();
write_enter(&mut entered).unwrap();
for sequence in ENTER {
for sequence in modes(ENTER) {
assert!(has(&entered, sequence), "{sequence:?} missing from enter {entered:?}");
}
let mut restored = Vec::new();
write_restore(&mut restored).unwrap();
for sequence in RESTORE {
for sequence in modes(RESTORE) {
assert!(has(&restored, sequence), "{sequence:?} missing from restore {restored:?}");
}
// The alternate screen is left last, so the user's screen returns after the modes are off.
@ -140,13 +147,13 @@ fn entering_writes_every_mode_and_restoring_undoes_each() {
fn dropping_the_guard_restores_once() {
let out = Shared::default();
let terminal = Terminal::enter_without_raw_mode(out.clone()).unwrap();
for sequence in ENTER {
for sequence in modes(ENTER) {
assert!(has(&out.bytes(), sequence), "{sequence:?}");
}
assert!(!has(&out.bytes(), "\x1b[?1049l"), "left before the guard dropped");
drop(terminal);
let bytes = out.bytes();
for sequence in RESTORE {
for sequence in modes(RESTORE) {
assert!(has(&bytes, sequence), "{sequence:?} missing after drop");
}
assert_eq!(count(&bytes, "\x1b[?1049l"), 1);
@ -162,7 +169,7 @@ fn a_panic_unwinding_through_the_guard_restores_the_terminal() {
}));
assert!(caught.is_err());
let bytes = out.bytes();
for sequence in RESTORE {
for sequence in modes(RESTORE) {
assert!(has(&bytes, sequence), "{sequence:?} missing after the panic");
}
}