Fix string-width miscalculation for single-cell UI symbols#784
Conversation
|
I just went over to fix the problem at the source (string-width library) solving this bug could be as easy as updating string-width to version 8.1.0. |
Also experiencing this right now. @okets Is that upgrade something you want to take on? If not I can also help out. |
The issue where single-cell UI symbols (▶, ◀, ⚠, ℹ) were miscalculated as two-cell characters originated in the string-width library. Updating from 7.2.0 to 8.1.0 resolves this bug at the source. This eliminates the need for the workaround patch previously implemented. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
@wu-json I just pushed my changes. waiting for someone to appove the PR. |
|
I tried patching Ink locally to use |
|
Line 64 in 9b21b24 |
Summary
Fixes an issue where common UI symbols (▶, ◀, ⚠, ℹ) were being incorrectly measured as width 2 by
string-width, causing layout breaks in fixed-width containers.Problem
The
string-widthlibrary uses the East Asian Width property, which marks certain common UI symbols as "Ambiguous". This causes them to be treated as wide characters (width 2) even though they display as single-width (width 1) in modern terminals.When these characters are used in Ink components, they cause:
Solution
Introduced a
SINGLE_WIDTH_OVERRIDESset that explicitly maps characters incorrectly measured bystring-widthto their correct width (1). The width calculation now checks this override map before falling back tostring-width.Changes
SINGLE_WIDTH_OVERRIDESconstant with verified single-width characterssrc/output.ts:227to check overrides firstTest Plan
string-widthincorrectly measures these as width 2