Repository navigation
Description
Summary
A red X moves by one cell in a two-column crop, yet the two serialized screen snapshots compare equal. A full-screen comparison catches the difference.
Reproduction
-
From the tagged
libvtcheckout, install the locked development dependencies withuv sync --frozen --python 3.14 --all-groups --all-extras. Use the checkout root as the working directory. -
Save the following as
case.pyat the checkout root.
from libvt import Terminal
from libvt.config import Profile, UnicodeBehavior
from libvt.testing import serialize_vt_snapshot, vt_screen
def snapshot(text):
terminal = Terminal(rows=1, cols=3)
terminal.feed(text.encode())
return terminal.committed
wide = snapshot("界\x1b[31mX")
plain = snapshot(" \x1b[31mX")
region = (0, 1, 1, 3)
print("crop cells", repr(wide[0:1, 1:3][0].display_text), repr(plain[0:1, 1:3][0].display_text))
a, b = (serialize_vt_snapshot(vt_screen(s, region=region)) for s in (wide, plain))
print("goldens equal", a == b)
assert serialize_vt_snapshot(wide) != serialize_vt_snapshot(plain)
custom = Terminal(rows=1, cols=4, profile=Profile(unicode=UnicodeBehavior(ambiguous_width=2)))
custom.feed("Ω\x1b[31mX".encode())
full = serialize_vt_snapshot(custom)
cropped = serialize_vt_snapshot(vt_screen(custom, region=(0, 1, 0, 4)))
print("red X in full and cropped view", "r0[2..3]: fg=red" in full, "r0[2..3]: fg=red" in cropped)
assert a != b, "a red X moved by one column inside the crop"- Run the case.
$ uv run --no-sync python case.pyExpected
The clipped continuation occupies one output column. The style span and red X move to different positions in the two regional goldens.
Actual
Different immutable slices serialize to the same box and color-span coordinates. A four-column full-width crop also moves X from column 2 to 1 when Ω takes two cells.
Environment
Tested versions
libvt v0.0.1a4 and trunk 0864aa2, CPython 3.14.6, Linux ARM64 on WSL2.
Evidence
Observed output
crop cells ' X' 'X '
goldens equal True
red X in full and cropped view True False
Proposal
Render a region from its actual cell positions and spacer roles. Retain its effective profile and grapheme mode so a full-width crop also respects ambiguous-width characters.
- Developer experience — Developers can keep focused regional goldens without an additional full-viewport assertion.
- Immediate benefit — Preserve the blank clipped cell and assert the red span before and after the one-column move.
- Longer-term benefit — The same golden comparison can remain reliable across East Asian, emoji and mixed-width layouts.
- End-user experience — A pane or modal layout regression produces a failure in the test that covers that region.
Activity
tony commentedon Dec 3, 2026
In local QA, cropping at either end of a wide cell preserved the selected columns. The narrow-edge case distinguishes
' X'and'X '. In the ambiguous-width case, the red X stays at display columns 2–3 after Ω in both the full frame and its full-width crop. The same scrubber implementation covers this and #143. Related PR #149