Skip to content

feat(tui): add width_method config option for ZWJ emoji handling#25942

Open
Flare576 wants to merge 1 commit intoanomalyco:devfrom
Flare576:feat/no-zwj-width-method
Open

feat(tui): add width_method config option for ZWJ emoji handling#25942
Flare576 wants to merge 1 commit intoanomalyco:devfrom
Flare576:feat/no-zwj-width-method

Conversation

@Flare576
Copy link
Copy Markdown

@Flare576 Flare576 commented May 6, 2026

Issue for this PR

Closes #6210

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

ZWJ emoji sequences (👩‍🚀 👨‍👩‍👧 🏳️‍🌈) corrupt terminal layout when the terminal doesn't render them as joined glyphs. tmux is the big one — text after a ZWJ sequence shifts across the screen, wraps wrong, and input box spacing breaks.

OpenTUI's Zig layer already has a no_zwj width mode that handles this correctly. It was already implemented, already tested. It just wasn't reachable from TypeScript. anomalyco/opentui#751 wires that up. This PR is the OpenCode side: a single config option that passes the user's preference through to the render() call.

Two files changed:

  • tui-schema.ts: adds width_method to TuiOptions ("unicode" | "wcwidth" | "no_zwj", optional)
  • app.tsx: passes _config.width_method to rendererConfig()

Users add one line to their opencode.json:

{
  "tui": {
    "width_method": "no_zwj"
  }
}

No default changes. Anyone not setting this gets identical behavior to today.

Note: depends on anomalyco/opentui#751. That PR's review feedback has been addressed and it's waiting on merge. Happy to wait, or if you want to merge this speculatively while that lands, the worst case is a no-op until opentui is bumped.

How did you verify your code works?

Ran OpenCode in a tmux split with the no_zwj config set. Family emoji and profession emoji that previously shifted subsequent text now render as split glyphs (👩 + 🚀 instead of 👩‍🚀) — visually imperfect, but correctly laid out. Terminals that do render ZWJ correctly can leave this unset and see no change.

Screenshots / recordings

No UI change visible without a terminal that exhibits the corruption. The fix is the absence of the corruption.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Some terminals (tmux, older terminals) do not render ZWJ emoji sequences
as joined glyphs, causing layout corruption when the width measurement
assumes joining. OpenTUI's Zig layer has a 'no_zwj' mode that handles
this correctly, but it was previously unreachable from the JavaScript API.

This depends on anomalyco/opentui#<PR> which exposes 'no_zwj' in the
WidthMethod type and wires it through the FFI boundary.

Add a 'width_method' option to the TUI config schema that passes through
to OpenTUI's render() call. Users experiencing layout corruption from ZWJ
emoji can opt in via their opencode.json:

  { "tui": { "width_method": "no_zwj" } }

No default is changed — existing behavior is fully preserved.
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.

[BUG] When using emojis, terminal output changes/shifts during scrolling

1 participant