Skip to content

Implements better character measurement. - #428

Merged
migueldeicaza merged 3 commits into
mainfrom
wcspec
Jan 7, 2026
Merged

Implements better character measurement.#428
migueldeicaza merged 3 commits into
mainfrom
wcspec

Conversation

@migueldeicaza

Copy link
Copy Markdown
Owner

For a while, we had a bit of a hodgepodge of attempts to measuring characters
properly. And I discovered ucs-detect [1] along with a spec for how terminal
emulators should measure unicode [2].

This patch implements that behavior.

Unicode width now comes from UCD properties + EastAsianWidth W/F ranges and
valid emoji‑variation sequences, and printing/combining now respects width ‑1/0
and only widens on valid VS16 (witha spacer cell) while dropping invalid
zero‑widths. We had a discussion last week on GitHub about some of these
problems, and my band-aid worked for a couple of things, but was by no means
comphrenesive.

[1] https://ucs-detect.readthedocs.io/intro.html
[2] https://wcwidth.readthedocs.io/en/latest/specs.html

The improvements are in:

https://gist.github.com/migueldeicaza/a81dc7fd5a31f10cd24b2ba60b28a083

See the bug for before/after screenshots.

This #427

This is an alterantive to the proposal in
#418 which was a follow
up to #409

Rather than special casing the keyboards that way, this improves the
existing UITextInput handling and it improves the chinese, japanese
and vietnamese output - but still fails with Korean.

I could not figure out why iOS refuses to let me participate in the
composition of text, even if the system seems to do just fine on its
own (like native UITextFields).

In particular this problem as documented by Nicolas:

> Korean input: ㅇ followed by ㅜ produces 우 (as expected), but ㅇ ㅜ ㅇ produces 우ㅇ instead of 웅.

So for Korean, I add a dreaded special case.
…aracters

properly.   And I discovered ucs-detect [1] along with a spec for how terminal
emulators should measure unicode [2].

This patch implements that behavior.

Unicode width now comes from UCD properties + EastAsianWidth W/F ranges and
valid emoji‑variation sequences, and printing/combining now respects width ‑1/0
and only widens on valid VS16 (witha spacer cell) while dropping invalid
zero‑widths.   We had a discussion last week on GitHub about some of these
problems, and my band-aid worked for a couple of things, but was by no means
comphrenesive.

[1] https://ucs-detect.readthedocs.io/intro.html
[2] https://wcwidth.readthedocs.io/en/latest/specs.html

The improvements are in:

https://gist.github.com/migueldeicaza/a81dc7fd5a31f10cd24b2ba60b28a083

See the bug for before/after screenshots.

This #427
@migueldeicaza
migueldeicaza merged commit 5e9b2e3 into main Jan 7, 2026
1 check passed
@migueldeicaza
migueldeicaza deleted the wcspec branch January 12, 2026 14:00
min-median-max pushed a commit to min-median-max/SwiftTerm that referenced this pull request Jan 18, 2026
For a while, we had a bit of a hodgepodge of attempts to measuring characters
properly. And I discovered ucs-detect [1] along with a spec for how terminal
emulators should measure unicode [2].

This patch implements that behavior.

Unicode width now comes from UCD properties + EastAsianWidth W/F ranges and
valid emoji‑variation sequences, and printing/combining now respects width ‑1/0
and only widens on valid VS16 (witha spacer cell) while dropping invalid
zero‑widths. We had a discussion last week on GitHub about some of these
problems, and my band-aid worked for a couple of things, but was by no means
comphrenesive.

[1] https://ucs-detect.readthedocs.io/intro.html
[2] https://wcwidth.readthedocs.io/en/latest/specs.html

The improvements are in:

https://gist.github.com/migueldeicaza/a81dc7fd5a31f10cd24b2ba60b28a083

See the bug for before/after screenshots.

This fixes migueldeicaza#427
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