Skip to content

fix(emu): count each unsupported shape past the bound once - #880

Merged
vyncint merged 2 commits into
vyncint:mainfrom
alvaroalonsoparrondo-a11y:fix/unsupported-overflow-distinct
Nov 27, 2026
Merged

vyncint merged 2 commits into
vyncint:mainfrom
alvaroalonsoparrondo-a11y:fix/unsupported-overflow-distinct

Conversation

@alvaroalonsoparrondo-a11y

Copy link
Copy Markdown
Contributor

Fixes #828

Once 32 shapes were kept, Unhandled::record added one to the overflow for every report of a shape it did not keep, repeats included. vt100 also reports an SGR or a DEC mode list once for each parameter it declines, so CSI 53 ; 59 m counted twice. The rustdoc says the overflow counts distinct shapes.

I took the issue's first option:

  • crates/termlens/src/emu/unhandled.rs: past the 32 retained, the record keeps the hashes of the shapes it has counted, at most MAX_OVERFLOW_TRACKED (256), and counts a shape only the first time. Past 256 such shapes it stops remembering new ones, so the memory stays bounded and a shape it does not remember counts each time, as before.
  • crates/termlens/src/screen.rs: the two doc lines on Unsupported and overflow() say that a shape counts once, exactly for the first 256 past the 32, and what happens after that.
  • Tests:
    • unit tests the_overflow_counts_each_shape_once (the issue's case: CSI 99 h three times and CSI 53 ; 59 m give 2) and the_overflow_remembers_a_bounded_number_of_shapes (the set stops at 256, a remembered shape still counts once, a later one counts again).
    • the issue's case end to end in tests/unsupported.rs, the_overflow_counts_distinct_shapes. Without the change it fails with left: 5, as in the issue. the_record_is_bounded (8 distinct past 32) still passes.
  • CHANGELOG: entry under Unreleased → Fixed.

Checked on macOS: cargo fmt --all --check, cargo clippy -p termlens --all-targets --all-features -- -D warnings, cargo test -p termlens --lib emu::unhandled, cargo test -p termlens --test unsupported, check-dco.sh and check-no-ai-attribution.sh.

Álvaro Alonso
242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com

Fixes vyncint#828

Signed-off-by: Álvaro Alonso <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com>
vyncint
vyncint previously approved these changes Nov 27, 2026

@vyncint vyncint left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against the issue; CI is green. Thank you.

Keep both integration tests in tests/unsupported.rs, vyncint#877's mode-list
test and this branch's overflow test, and the CHANGELOG entries without
a blank line between them.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
@vyncint
vyncint merged commit c086791 into vyncint:main Nov 27, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsupported::overflow counts every report past the bound, not the distinct shapes its rustdoc promises

2 participants