Reorder right-to-left text per row from the alpha, the way COSMIC Terminal does
Status: superseded by 0007. Date: 2026-11-06.
Arabic is supported from day 0. Programs write Arabic in logical order. Terminals
that only place cells left to right (Alacritty, Ghostty, Windows Terminal, kitty)
show it reversed and, without shaping across cells, unjoined. The owner compared
Alacritty, COSMIC Terminal, Ghostty and GNOME Terminal on ls and bat with an
Arabic file name and contents: COSMIC's rendering was preferred. COSMIC gets there
by laying out each row through cosmic-text, which runs the Unicode Bidirectional
Algorithm and shapes the runs. Voyager7 already uses cosmic-text. There is no settled
standard for bidi in a monospace terminal; the "BiDi in Terminal Emulators"
recommendation, which GNOME's VTE implements, is the closest prior art, and Unicode
work on it continues.
Decision
- The VT grid stays in logical order. libghostty-vt is not changed and its cells, cursor and wrapping are logical.
- The Renderer resolves each row with UAX #9 at a left-to-right base level, reorders right-to-left runs into visual order as whole cells (wide cells move as units), shapes each run with joining across cells, and places each cluster at its visual cell. Rows with no strong right-to-left character skip this entirely.
- Each row keeps its logical-to-visual cell map. The cursor is drawn at the visual position of its logical cell; selection and mouse hit-testing map through the same table, so copying text yields logical order.
- Box drawing and other neutrals between left-to-right text keep their columns, so
tables like
bat's borders stay aligned. - A config switch turns reordering off for programs that do their own bidi. The escape sequences from the recommendation (letting a full-screen program switch a row or the screen to explicit mode) come after the alpha.
Consequences
- Cost is per dirty row with right-to-left content, cached until the row changes, so ordinary output pays only the "any strong RTL character?" scan.
- Tests: CPU reference goldens for an English line, an Arabic line and a mixed line (owner approved), plus property tests that the visual map is a permutation, that cursor and selection round-trip, and that left-to-right-only rows are untouched.
- Emoji: the owner considers Ghostty's emoji handling the reference (presentation, width and color); our emoji tests compare against that behavior.