diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba1966..60a2053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,13 @@ reads that marker. reports motion only when the pointer enters another cell, so an application that tells a click from a drag by a motion report saw a drag where a terminal delivers a click. (#834) +- `unsupported()` no longer lists a DEC private mode list that pairs a + mode vt100 carries out with one termlens tracks, such as + `CSI ? 2004 ; 1004 h` or `CSI ? 25 ; 2026 h`. Every mode in it took + effect, but the list was judged by the tracked modes alone, so a + program that set its modes in one sequence could never have an empty + record. A list with a mode nobody honours, such as `CSI ? 25 ; 12 h`, + is still listed. (#829) - Both published crates, `termlens` and `termlens-cli`, ship `LICENSE-MIT` and `LICENSE-APACHE`. They are `MIT OR Apache-2.0`, and both licences ask for their text in every copy, but the texts sat only at the repository diff --git a/crates/termlens/src/emu/unhandled.rs b/crates/termlens/src/emu/unhandled.rs index 4a0509a..e4eb174 100644 --- a/crates/termlens/src/emu/unhandled.rs +++ b/crates/termlens/src/emu/unhandled.rs @@ -297,6 +297,12 @@ fn osc_shape(params: &[&[u8]], dropped: bool) -> String { /// console's handshake in every Windows snapshot's list (#149). const TRACKED_PRIVATE_MODES: &[u16] = &[9, 1000, 1002, 1003, 1005, 1006, 1015, 1004, 2026, 9001]; +/// DEC private modes vt100's own `decset` and `decrst` carry out. vt100 +/// hands the whole list to `unhandled_csi` for each mode in it that it +/// declines, so a list that pairs one of these with a tracked mode reaches +/// the record though every mode in it took effect (#829). +const VT100_PRIVATE_MODES: &[u16] = &[1, 6, 9, 25, 47, 1000, 1002, 1003, 1005, 1006, 1049, 2004]; + /// DECAWM, autowrap. Setting it asks for the only behaviour the emulator /// has, so `CSI ? 7 h` — which ncurses sends at every start (`smam`) — is /// honoured; resetting it is not modelled, and stays on record (#581). @@ -510,12 +516,14 @@ impl Callbacks for Unhandled { (Some(b'?' | b'='), None, 'n') => true, (Some(b'='), None, 'c') => matches!(first, None | Some(0)), (Some(b'>'), None, 'q') => params == [&[0][..]], - // The private modes the tracker keeps; any other private mode - // vt100 declined is one nobody honoured. - (Some(b'?'), None, 'h' | 'l') => params - .iter() - .flat_map(|p| p.iter()) - .all(|m| TRACKED_PRIVATE_MODES.contains(m) || (c == 'h' && *m == AUTOWRAP)), + // The private modes the tracker keeps, beside the ones vt100 + // carries out itself; any other private mode vt100 declined is + // one nobody honoured. + (Some(b'?'), None, 'h' | 'l') => params.iter().flat_map(|p| p.iter()).all(|m| { + TRACKED_PRIVATE_MODES.contains(m) + || VT100_PRIVATE_MODES.contains(m) + || (c == 'h' && *m == AUTOWRAP) + }), _ => false, }; if handled { @@ -642,6 +650,31 @@ mod tests { assert_eq!(shapes(b"\x1b[?7;12h"), ["^[[?7;12h"]); } + /// vt100 hands the whole list on for each mode it declines, so a list + /// that pairs one of its own modes with a tracked one was listed, + /// though every mode in it took effect (#829). + #[test] + fn a_mode_list_of_vt100_and_tracked_modes_is_not_listed() { + for list in [ + &b"\x1b[?2004;1004h"[..], + b"\x1b[?25;2026h\x1b[?2026l", + b"\x1b[?7;25h", + b"\x1b[?1;1015h", + b"\x1b[?1049;1004h", + b"\x1b[?6;9;47;1004l", + ] { + assert_eq!( + shapes(list), + [] as [String; 0], + "{}", + String::from_utf8_lossy(list) + ); + } + // A mode nobody honours still puts its list on record. + assert_eq!(shapes(b"\x1b[?25;12h"), ["^[[?25;12h"]); + assert_eq!(shapes(b"\x1b[?7;25l"), ["^[[?7;25l"]); + } + #[test] fn a_sequence_nobody_honours_is_recorded_once_in_its_written_form() { assert_eq!( diff --git a/crates/termlens/tests/unsupported.rs b/crates/termlens/tests/unsupported.rs index 8b0f905..523c48b 100644 --- a/crates/termlens/tests/unsupported.rs +++ b/crates/termlens/tests/unsupported.rs @@ -104,6 +104,37 @@ fn a_semicolon_title_is_honoured_and_a_mode_list_is_judged_whole() -> termlens:: Ok(()) } +/// A DEC mode list that pairs one of vt100's own modes with one the tracker +/// keeps is not listed: every mode in it took effect (#829). One mode +/// nobody honours still puts its list on record. +#[test] +#[cfg_attr( + windows, + ignore = "ConPTY renders what it implements and drops the rest before termlens sees a byte, so the record there is the console's, not the application's (#149)" +)] +fn a_list_of_honoured_modes_is_not_listed() -> termlens::Result<()> { + let mut t = emit(&[ + "--raw", + r"\e[?2004;1004h\e[?25;2026h\e[?2026l\e[?7;25h\e[?1;1015h\e[?1049;1004h", + "DONE", + "--wait", + ])?; + t.wait_until(|s| s.contains("DONE"))?; + let s = t.screen(); + assert!(s.bracketed_paste() && s.focus_events(), "{s}"); + assert!(s.application_cursor() && s.alternate_screen(), "{s}"); + assert_eq!(shapes(&t), Vec::::new(), "{s}"); + t.send(Key::Enter)?; + assert!(t.wait_exit()?.success()); + + let mut t = emit(&["--raw", r"\e[?25;12h", "DONE", "--wait"])?; + t.wait_until(|s| s.contains("DONE"))?; + assert_eq!(shapes(&t), ["^[[?25;12h"], "{}", t.screen()); + t.send(Key::Enter)?; + assert!(t.wait_exit()?.success()); + Ok(()) +} + /// A visual bell is a different event from an audible one, and a request to /// resize the window is recorded rather than honoured. #[test]