diff --git a/CHANGELOG.md b/CHANGELOG.md index 7adac6d..d4569c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,11 @@ reads that marker. that writes 0-255 values gives, is ignored and the register keeps its colour, as xterm does. Each component was clamped to 100 and applied, so the image decoded in colours xterm never shows. (#845) +- A kitty placement decides whether it moves the cursor by the values of + `U=` and `P=`, as kitty does. `P=0` names no parent, so it moves the + cursor, and any nonzero `U=` makes the placement virtual, so it does + not; termlens took `P=` by its presence and `U=` only at 1, so the text + a client wrote after `P=0` landed on the image. (#844) - 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/vt100.rs b/crates/termlens/src/emu/vt100.rs index 9269d52..0587068 100644 --- a/crates/termlens/src/emu/vt100.rs +++ b/crates/termlens/src/emu/vt100.rs @@ -165,7 +165,7 @@ impl Vt100Emulator { /// /// kitty moves it right by the placement's columns and down by its rows /// less one — onto the image's last row, one column past it — for a - /// placement that asks (no `C=1`, `U=1` or `P=`). xterm, with sixel + /// placement that asks (no `C=1`, nonzero `U=` or nonzero `P=`). xterm, with sixel /// scrolling on as it is by default, moves it down to the image's last /// text row and leaves the column. Each ignores the other's escape. fn image_step(&self, payload: &GraphicsPayload, placement: &Placement) -> Option { diff --git a/crates/termlens/src/graphics.rs b/crates/termlens/src/graphics.rs index ab9e4e0..65e230f 100644 --- a/crates/termlens/src/graphics.rs +++ b/crates/termlens/src/graphics.rs @@ -1218,8 +1218,9 @@ pub(crate) struct Placement { pub(crate) cell_x: u32, pub(crate) cell_y: u32, /// kitty: whether a placement moves the cursor at all. `C=1` asks it not - /// to, and neither a Unicode-placeholder placement (`U=1`) nor one - /// relative to another image (`P=`) moves it. + /// to, and neither a Unicode-placeholder placement (a nonzero `U=`) nor + /// one relative to another image (a nonzero `P=`) moves it. kitty reads + /// both by value, so `P=0` and `U=0` name no parent and no placeholder. pub(crate) moves: bool, /// sixel: the image's height in pixels as xterm measures it, the larger /// of the raster attributes' and the painted rows'. @@ -1330,7 +1331,7 @@ impl GraphicsBuilder { src_y: value(b"y"), cell_x: value(b"X"), cell_y: value(b"Y"), - moves: value(b"C") != 1 && value(b"U") != 1 && key(control, b"P").is_none(), + moves: value(b"C") != 1 && value(b"U") == 0 && value(b"P") == 0, height: 0, forgets: None, number: value(b"I"), @@ -1783,6 +1784,23 @@ mod tests { } } + /// kitty decides by value: `P=0` names no parent and `U=0` no + /// placeholder, so both move the cursor, while any nonzero `U=` makes + /// the placement virtual (`handle_put_command`, #844). + #[test] + fn p_and_u_decide_the_cursor_move_by_value() { + let moves = |control: &[u8]| { + let mut builder = GraphicsBuilder::default(); + builder.kitty(control); + builder.chunk(0, b"", true, usize::MAX); + builder.finish_placed().expect("a payload").1.moves + }; + assert!(moves(b"a=T,c=3,r=2,P=0")); + assert!(moves(b"a=T,c=3,r=2,U=0")); + assert!(!moves(b"a=T,c=3,r=2,U=2")); + assert!(!moves(b"a=T,c=3,r=2,P=1")); + } + /// What a delete frees, as kitty's `handle_delete_command` frees it: /// only the upper-case deletes by id say so on their own, and only /// without `p=` (#672). Every other escape forgets nothing. diff --git a/crates/termlens/tests/graphics.rs b/crates/termlens/tests/graphics.rs index d00e157..8826e85 100644 --- a/crates/termlens/tests/graphics.rs +++ b/crates/termlens/tests/graphics.rs @@ -335,3 +335,30 @@ fn a_declared_kitty_terminal_moves_the_cursor_past_a_placement() -> termlens::Re } Ok(()) } + +/// kitty reads `P=` and `U=` by value: `P=0` names no parent, so the +/// placement moves the cursor, and `U=2` is a virtual placement, which does +/// not (#844). +#[test] +#[cfg_attr( + windows, + ignore = "ConPTY does not forward kitty or sixel payloads (#149)" +)] +fn p_and_u_decide_the_cursor_move_by_value() -> termlens::Result<()> { + for (key, expected) in [("P=0", (1, 3)), ("U=2", (0, 0))] { + let escape = format!(r"\e_Ga=T,f=24,s=1,v=1,c=3,r=2,{key};ESIz\e\\X"); + let mut t = util::spawn_emit( + Terminal::builder() + .size(20, 5) + .timeout(Duration::from_secs(30)) + .graphics(termlens::Graphics::Kitty) + .cell_size(10, 20), + &["--raw", escape.as_str(), "--wait"], + )?; + t.wait_until(|s| s.contains("X"))?; + assert_eq!(t.screen().find("X"), Some(expected), "{key}"); + t.send(termlens::Key::Enter)?; + t.wait_exit()?; + } + Ok(()) +} diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 349e20a..945f5ef 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -925,7 +925,7 @@ Rules: declared (`graphics()`, with `cell_size()`; #588): kitty puts it on the placement's last row, one column past its right edge, wrapping to the next row past the screen's and scrolling past the bottom margin, unless - `C=1`, `U=1` or `P=` says otherwise; xterm, with sixel scrolling on as it + `C=1`, a nonzero `U=` or a nonzero `P=` says otherwise; xterm, with sixel scrolling on as it is by default, puts it on the image's last text row and leaves the column. A terminal declared without the protocol ignores the escape and moves nothing, which is the default. The cursor is moved with line feeds