Add ambiguouswidth option - #4206
Conversation
The width of characters with the East Asian Ambiguous width property is currently decided by the locale environment variables, since that is what go-runewidth autodetects. Terminals usually draw these characters one column wide regardless of the locale, so in an East Asian locale micro misaligns the text and puts the cursor in the wrong column, with no way to override it. Add a global-only `ambiguouswidth` option, in the same shape as `truecolor`: `auto` (the default, i.e. the current behavior), `single` and `double`.
There was a problem hiding this comment.
This PR seems like AI slop but this part does actually seem to fix the problem:
runewidth.DefaultCondition.EastAsianWidth = runewidth.EastAsianWidthHowever I'm not sure what the use case for the ambiguouswidth setting is, couldn't we simply set runewidth.DefaultCondition.EastAsianWidth in the init function in util.go?
Or, even better, just update our go-runewidth dependency. The latest version does something equivalent automatically. (EDIT: nevermind, the old version also does it automatically so this PR is just nonsense – the dependency update that actually helped was tcell, not go-runewidth)
Writing runewidth.EastAsianWidth has no effect on measurement: go-runewidth reads DefaultCondition, and syncs it from that package variable only once in its own init(). Drop the redundant write and keep the assignment that matters.
|
Re-ran all of this on a fresh clone of 1. That line was in the first commit; 2. Updating the dependency does not help. v0.0.21 autodetects the same way, it just as automatically decides double: 3. Issue 2 of #1124 is therefore still live on master. pty capture, master and Why a setting instead of a hardcoded vim/nano therefore assume one column, and @dmaluka reports that looking worse than micro's current double in their setup, which implies a terminal that draws these two columns wide, while yours draws them one. That is exactly the split vim's I am happy to flip the default to Test status: Not verified, stated as such: musl's |
Description
Characters with the East Asian Ambiguous width property (Greek, Cyrillic, accented Latin) are measured as two columns whenever
LANG/LC_*names a CJK locale, as go-runewidth autodetects. Most terminals draw them one column wide, so text is misaligned and the cursor sits in the wrong column (#1124). This adds anambiguouswidthoption, shaped aftertruecolor.Measured in a pty,
LANG=ja_JP.UTF-8, bufferlet αβγ = 0: withautotcell moves two columns per rune (α ESC[1;9H β ESC[1;11H γ ESC[1;13H, cursor ends at column 17); withsinglethe runes are contiguous and the cursor ends at column 14. glibc 2.39 and musl 1.2.5wcwidth()both return 1 for these code points underja_JP.UTF-8, so the doubling is micro's choice, not libc's.Open question: the default. I kept
auto, so nothing changes;singlewould match wcwidth and the editors mentioned in the issue.User-Facing Changes
New global-only option
ambiguouswidth(auto/single/double), applied onsetand documented inoptions.md. Nothing changes at the default.Tests
TestSetAmbiguousWidthininternal/util;go test ./...passes. Mutation-checked: makingsingleset wide, or dropping theDefaultConditionsync, each turns it red. Also reconciled against the UAX #11 15.1.0 file (what go-runewidth v0.0.16 is generated from): of its 138,739 Ambiguous code points, 138,626 flip 1->2 and 113 are zero-width combining marks; 0 of 209,089 non-Ambiguous ones change.