[PR #751] feat(core): expose no_zwj as opt-in WidthMethod #756

Open
opened 2026-03-02 23:47:59 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/751
Author: @Flare576
Created: 2/27/2026
Status: 🔄 Open

Base: mainHead: feat/no-zwj-width-method


📝 Commits (1)

  • 47cc0c2 feat(core): expose no_zwj as opt-in WidthMethod option

📊 Changes

4 files changed (+11 additions, -11 deletions)

View changed files

📝 packages/core/src/renderer.ts (+1 -1)
📝 packages/core/src/types.ts (+1 -1)
📝 packages/core/src/zig.ts (+4 -4)
📝 packages/core/src/zig/lib.zig (+5 -5)

📄 Description

Problem

ZWJ emoji sequences (👩‍🚀 👨‍👩‍👧 🏳️‍🌈) cause layout corruption in terminals that don't render them as joined glyphs — most notably tmux, but also many older terminals. Text after a ZWJ sequence shifts across the screen, wraps incorrectly, and input box spacing breaks.

The no_zwj width calculation mode already exists in the Zig layer, is fully implemented, and has comprehensive test coverage (utf8_no_zwj_test.zig). The environment variable OPENTUI_FORCE_NOZWJ is already registered and wired through terminal.zig. However, no_zwj is missing from the TypeScript WidthMethod union type and from the numeric mapping at the FFI boundary, making it completely unreachable from JavaScript consumers.

Solution

Wire no_zwj through the full TypeScript→FFI chain without changing any defaults:

  • packages/core/src/types.ts: Add "no_zwj" to the WidthMethod union
  • packages/core/src/zig.ts: Map "no_zwj"2 in the four widthMethodCode conversions (previously only 0/1 existed)
  • packages/core/src/zig/lib.zig: Map u8 value 2.no_zwj in the four FFI entry points; map .no_zwj2 in getTerminalCapabilities serialization
  • packages/core/src/renderer.ts: Update the widthMethod getter to return "no_zwj" when capabilities report 2 (e.g. via OPENTUI_FORCE_NOZWJ)

Behavior

Mode ZWJ emoji (👩‍🚀) Skin tones (👋🏿) Flags (🇺🇸) Accents (é)
unicode (default, unchanged) 1 glyph, 2 cols 1 glyph, 2 cols 1 glyph, 2 cols 1 glyph, 1 col
no_zwj (opt-in) 2 glyphs, 4 cols 1 glyph, 2 cols 1 glyph, 2 cols 1 glyph, 1 col

Only ZWJ-joined sequences are affected. Skin tone modifiers, regional indicator flags, combining accents, and CJK characters are all unaffected.

No Breaking Changes

  • Default is still "unicode" everywhere
  • "wcwidth" behavior is unchanged
  • OPENTUI_FORCE_NOZWJ env var now correctly round-trips through getTerminalCapabilitieswidthMethod getter
  • Existing consumers passing "wcwidth" or "unicode" see identical behavior

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/751 **Author:** [@Flare576](https://github.com/Flare576) **Created:** 2/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/no-zwj-width-method` --- ### 📝 Commits (1) - [`47cc0c2`](https://github.com/anomalyco/opentui/commit/47cc0c2cd0f0b8f20fd0e9d91b1d242204ca7e7a) feat(core): expose no_zwj as opt-in WidthMethod option ### 📊 Changes **4 files changed** (+11 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/renderer.ts` (+1 -1) 📝 `packages/core/src/types.ts` (+1 -1) 📝 `packages/core/src/zig.ts` (+4 -4) 📝 `packages/core/src/zig/lib.zig` (+5 -5) </details> ### 📄 Description ## Problem ZWJ emoji sequences (👩‍🚀 👨‍👩‍👧 🏳️‍🌈) cause layout corruption in terminals that don't render them as joined glyphs — most notably tmux, but also many older terminals. Text after a ZWJ sequence shifts across the screen, wraps incorrectly, and input box spacing breaks. The `no_zwj` width calculation mode already exists in the Zig layer, is fully implemented, and has comprehensive test coverage (`utf8_no_zwj_test.zig`). The environment variable `OPENTUI_FORCE_NOZWJ` is already registered and wired through `terminal.zig`. However, `no_zwj` is missing from the TypeScript `WidthMethod` union type and from the numeric mapping at the FFI boundary, making it completely unreachable from JavaScript consumers. ## Solution Wire `no_zwj` through the full TypeScript→FFI chain without changing any defaults: - **`packages/core/src/types.ts`**: Add `"no_zwj"` to the `WidthMethod` union - **`packages/core/src/zig.ts`**: Map `"no_zwj"` → `2` in the four `widthMethodCode` conversions (previously only `0`/`1` existed) - **`packages/core/src/zig/lib.zig`**: Map `u8` value `2` → `.no_zwj` in the four FFI entry points; map `.no_zwj` → `2` in `getTerminalCapabilities` serialization - **`packages/core/src/renderer.ts`**: Update the `widthMethod` getter to return `"no_zwj"` when capabilities report `2` (e.g. via `OPENTUI_FORCE_NOZWJ`) ## Behavior | Mode | ZWJ emoji (👩‍🚀) | Skin tones (👋🏿) | Flags (🇺🇸) | Accents (é) | |---|---|---|---|---| | `unicode` (default, unchanged) | 1 glyph, 2 cols | 1 glyph, 2 cols | 1 glyph, 2 cols | 1 glyph, 1 col | | `no_zwj` (opt-in) | 2 glyphs, 4 cols | 1 glyph, 2 cols | 1 glyph, 2 cols | 1 glyph, 1 col | Only ZWJ-joined sequences are affected. Skin tone modifiers, regional indicator flags, combining accents, and CJK characters are all unaffected. ## No Breaking Changes - Default is still `"unicode"` everywhere - `"wcwidth"` behavior is unchanged - `OPENTUI_FORCE_NOZWJ` env var now correctly round-trips through `getTerminalCapabilities` → `widthMethod` getter - Existing consumers passing `"wcwidth"` or `"unicode"` see identical behavior ## Related - Related to #609 (emoji wrap corruption at line boundaries) - Companion PR for OpenCode to expose this as a user config option: https://github.com/Flare576/opencode/tree/feat/no-zwj-width-method --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#756
No description provided.