Skip to content

Terminal: count East Asian Wide characters as two columns - #2894

Open
insjang wants to merge 1 commit into
eclipse-platform:masterfrom
insjang:eaw-width
Open

Terminal: count East Asian Wide characters as two columns#2894
insjang wants to merge 1 commit into
eclipse-platform:masterfrom
insjang:eaw-width

Conversation

@insjang

@insjang insjang commented Sep 2, 2026

Copy link
Copy Markdown

The terminal emulator assumes every character occupies one cell. Hangul, Han and Kana text, fullwidth forms and emoji are East Asian Wide and occupy two, so every such character put the cursor one column short and the screen fell apart as soon as a program laid text out for a real terminal — line editors, curses UIs, Ink-based CLIs.

This adds CharWidth, a UAX #11 East Asian Width lookup (Wide/Fullwidth = 2, combining marks and controls = 0, Ambiguous = 1 as UAX #11 recommends outside an East Asian legacy context), and makes the emulator and renderer follow it:

  • the cursor advances by width; the second cell of a wide character holds a NUL filler
  • a wide character is never split across the right margin
  • overwriting either half of a wide character blanks the other half
  • insert mode counts cells, not characters
  • the renderer skips fillers so a fixed-width font draws the glyph over both cells, falls back to placing each character at its own cell when the font does not advance exactly one cell per column, and draws characters beyond the BMP whole
  • a partial repaint starting on the second cell of a wide character is widened to its first
  • copying drops the fillers

Tests: CharWidthTest (width table) and four cases in VT100EmulatorBackendTest (placement, margin, overwriting halves, insert mode). All existing terminal tests pass.

Verified on Windows 11 with a Korean shell session, vim, htop and Claude Code inside the Eclipse Terminal; compared against Windows Terminal for column alignment.

The emulator assumed every character occupies one cell, so Hangul, Han
and Kana text, fullwidth forms and emoji were placed one column short
per character and the screen fell apart as soon as a program laid text
out for a real terminal (line editors, curses UIs, Ink based CLIs).

Add CharWidth, a UAX eclipse-platform#11 East Asian Width lookup: Wide and Fullwidth
count as two columns, combining marks and controls as zero, Ambiguous as
one, as UAX eclipse-platform#11 recommends outside an East Asian legacy context.

The emulator advances the cursor by that width and stores a NUL filler
in the second cell of a wide character, never splits one across the
right margin, blanks the other half when either half is overwritten and
counts insert mode in cells. The renderer skips the fillers so a fixed
width font draws a wide glyph over both cells, falls back to placing
each character at its own cell when the font does not advance exactly
one cell per column, and draws a character beyond the BMP whole. A
partial repaint that starts on the second cell of a wide character is
widened to its first, and copying drops the fillers.

Tests cover the width table, placement, the margin, overwriting halves
and insert mode.
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