Add ambiguouswidth option - #4206
Open
aron-intframe wants to merge 1 commit into
Open
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`.
Andriamanitra
suggested changes
Sep 2, 2026
Collaborator
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.