Skip to content

rust: measure text with the width method the terminal reports - #1955

Merged
simonklee merged 1 commit into
mainfrom
harden/448-rust-app-width-method-stale
Nov 9, 2026
Merged

simonklee merged 1 commit into
mainfrom
harden/448-rust-app-width-method-stale

Conversation

@simonklee

Copy link
Copy Markdown
Member

App cached its width method before the terminal answered the startup queries. When a reply changed it, as ConPTY's DECRPM 2027 "unrecognized" answer switches drawing to wcwidth, native drawing followed but App::width_method() did not. Widgets then measured a ZWJ emoji as 2 cells and drew 4: a right-aligned table cell blanked it, a gutter sign was clipped, and an input created later wrote over part of the emoji. A Scrollback's app and its session followed only at their next render, so text, Markdown and code built after the reply wrapped as before it. With OPENTUI_FORCE_NOZWJ, it reported NoZwj, which native draws as Unicode.

App::width_method() now reads the session's capabilities on each call, as Core's widthMethod does. A Scrollback's app copies its parent's terminal state, hyperlink support included, before it reads it or makes a node, as Core does. NoZwj reads as Unicode, as in Core. The line-number gutter measures its signs again when the method changes, as Core's LineNumberRenderable does.

A remote-terminal test covers wcwidth, back to Unicode, Ghostty's wide mode and NoZwj, checking a table, a gutter sign, scrollback snapshots of text, Markdown, code and a link, an input created after the reply, and the cursor.

App cached its width method before the terminal's startup replies
arrived. When a reply changed it, as ConPTY's DECRPM 2027 "unrecognized"
answer switches drawing to wcwidth, native drawing followed but
App::width_method() did not. Widgets then measured a ZWJ emoji as 2
cells and drew 4: a right-aligned table cell blanked it, a gutter sign
was clipped, and an input created later wrote over part of it. A
scrollback writer's detached app and its native session followed only
at its next render, so text, Markdown and code built after the reply
wrapped as before it.

App::width_method() now reads the session's capabilities on each call,
as App::hyperlinks() and Core's widthMethod do, and the cached copy is
gone. A scrollback writer's detached app copies its parent's terminal
state before it reads it or makes a native node, as Core syncs before
it builds a scrollback snapshot. NoZwj reads as Unicode, which native
draws it with, as Core does. The line-number gutter remembers the method
it measured its signs with and measures them again when it changes, as
Core's LineNumberRenderable does.

Source lines added: the parent session and the copy before reads and new
nodes, skipped while a frame runs (14), the NoZwj arm and its comment
(4), and the gutter's remembered method (6), against 10 removed with the
cache.

Issue: 448
@simonklee
simonklee requested a review from kommander as a code owner November 9, 2026 04:15
@simonklee
simonklee merged commit 841adff into main Nov 9, 2026
26 checks passed
@simonklee
simonklee deleted the harden/448-rust-app-width-method-stale branch November 9, 2026 05:27
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.

1 participant