Skip to content

Add ambiguouswidth option - #4206

Open
aron-intframe wants to merge 1 commit into
micro-editor:masterfrom
aron-intframe:ambiguous-width
Open

Add ambiguouswidth option#4206
aron-intframe wants to merge 1 commit into
micro-editor:masterfrom
aron-intframe:ambiguous-width

Conversation

@aron-intframe

Copy link
Copy Markdown

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 an ambiguouswidth option, shaped after truecolor.

Measured in a pty, LANG=ja_JP.UTF-8, buffer let αβγ = 0: with auto tcell moves two columns per rune (α ESC[1;9H β ESC[1;11H γ ESC[1;13H, cursor ends at column 17); with single the runes are contiguous and the cursor ends at column 14. glibc 2.39 and musl 1.2.5 wcwidth() both return 1 for these code points under ja_JP.UTF-8, so the doubling is micro's choice, not libc's.

Open question: the default. I kept auto, so nothing changes; single would match wcwidth and the editors mentioned in the issue.

User-Facing Changes

New global-only option ambiguouswidth (auto/single/double), applied on set and documented in options.md. Nothing changes at the default.

Tests

TestSetAmbiguousWidth in internal/util; go test ./... passes. Mutation-checked: making single set wide, or dropping the DefaultCondition sync, 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.

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 Andriamanitra left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems like AI slop but this part does actually seem to fix the problem:

runewidth.DefaultCondition.EastAsianWidth = runewidth.EastAsianWidth

However 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)

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.

2 participants