beer/graphics: match continuation chunks against in-flight transmission

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If3d05c2263211cdf8329394741d22a5f6a6a6964
This commit is contained in:
raf 2026-06-27 00:19:56 +03:00
commit 08f788dfae
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF

View file

@ -233,7 +233,9 @@ impl Graphics {
/// displays. /// displays.
fn transmit(&mut self, cmd: GraphicsCommand, payload: &[u8], cell_px: (u32, u32)) -> Outcome { fn transmit(&mut self, cmd: GraphicsCommand, payload: &[u8], cell_px: (u32, u32)) -> Outcome {
// Continuation chunk: append to the in-flight transmission. // Continuation chunk: append to the in-flight transmission.
if self.pending.is_some() && is_continuation(&cmd) { if let Some(pending) = &self.pending
&& is_continuation(&cmd, pending)
{
return self.accumulate(cmd, payload, cell_px); return self.accumulate(cmd, payload, cell_px);
} }
if cmd.more { if cmd.more {
@ -591,13 +593,17 @@ impl Graphics {
} }
/// Whether a command is a continuation chunk of the in-flight transmission /// Whether a command is a continuation chunk of the in-flight transmission
/// rather than a fresh command: it carries no id, number, or geometry, only the /// rather than a fresh command: it carries no geometry or format keys, only
/// `m`/`q` (and, for frames, `a=f`) keys. Both image and animation-frame /// `m`/`q` (and, for frames, `a=f`). Both image and animation-frame
/// transmissions chunk this way. /// transmissions chunk this way.
fn is_continuation(cmd: &GraphicsCommand) -> bool { ///
/// The spec says continuation chunks omit `i`/`I`, but some senders (e.g.
/// kitty's icat) repeat the image id on every chunk. Accept those too, as
/// long as the id matches the in-flight transmission.
fn is_continuation(cmd: &GraphicsCommand, pending: &Pending) -> bool {
matches!(cmd.action, Action::Transmit | Action::Frame) matches!(cmd.action, Action::Transmit | Action::Frame)
&& cmd.id == 0 && (cmd.id == 0 || cmd.id == pending.cmd.id)
&& cmd.number == 0 && (cmd.number == 0 || cmd.number == pending.cmd.number)
&& cmd.format == Format::Rgba && cmd.format == Format::Rgba
&& cmd.width == 0 && cmd.width == 0
&& cmd.height == 0 && cmd.height == 0