fix(tui): inject VS16 so text-default emoji render as color glyphs

Models frequently emit bare codepoints like U+26A0 (⚠), U+2139 (ℹ),
U+2764 (❤), U+2714 (✔), U+2600 (☀), U+263A (☺) which, per Unicode, have
Emoji_Presentation=No and render as monochrome text-style glyphs in
terminals unless followed by VS16 (U+FE0F). Agent output leaked through
the TUI like `⚠ careful` instead of `⚠️ careful`.

Added `ensureEmojiPresentation` (lib/emoji.ts): scans for the curated
set of text-default codepoints and appends VS16 when the next char is
not already VS16, ZWJ, or a keycap-enclosing mark. Idempotent and
fast-pathed by a Unicode-range regex so ASCII-heavy text is untouched.

Applied once at the top of `Md`'s line parse. Hermes-ink's stringWidth
already accounts for VS16, so cursor/layout stays correct.
This commit is contained in:
Brooklyn Nicholson 2026-04-20 20:12:10 -05:00
parent 12c7f279d6
commit 136519a2c9
3 changed files with 121 additions and 1 deletions

View file

@ -1,6 +1,7 @@
import { Box, Link, Text } from '@hermes/ink'
import { memo, type ReactNode, useMemo } from 'react'
import { ensureEmojiPresentation } from '../lib/emoji.js'
import { highlightLine, isHighlightable } from '../lib/syntax.js'
import type { Theme } from '../theme.js'
@ -232,7 +233,7 @@ interface MdProps {
function MdImpl({ compact, t, text }: MdProps) {
const nodes = useMemo(() => {
const lines = text.split('\n')
const lines = ensureEmojiPresentation(text).split('\n')
const nodes: ReactNode[] = []
let i = 0