[PR #256] [CLOSED] Fix CJK character corruption in text rendering #1181

Closed
opened 2026-03-14 09:22:40 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/256
Author: @zenyr
Created: 11/3/2025
Status: Closed

Base: mainHead: fix/cjk-character-corruption


📝 Commits (2)

  • 448dbfe fix: cjk character corruption in text rendering
  • d536896 test: add fromString default color validation tests for CJK support

📊 Changes

6 files changed (+568 additions, -1 deletions)

View changed files

📝 packages/core/src/renderables/TextNode.test.ts (+58 -0)
📝 packages/core/src/renderables/TextNode.ts (+8 -1)
packages/core/src/tests/cjk-rendering.test.ts (+251 -0)
📝 packages/react/src/index.ts (+1 -0)
packages/react/src/testing.ts (+37 -0)
packages/react/tests/cjk-unicode.test.tsx (+213 -0)

📄 Description

Summary

This PR fixes the root cause of CJK character corruption (#255) by modifying the renderer to skip continuation cells instead of writing space placeholders.

Root Cause Analysis

CJK characters (width=2) occupy 2 terminal columns but are stored as 1 cell in the buffer. The original implementation had a fundamental issue:

  1. CJK character rendered at cell position x
  2. Continuation cell at (x+1) marked as occupied
  3. Space character written at continuation cell overwrites the next actual character
  4. Result: CJK corruption

Changes in Latest Commit

renderer.zig (6449abb):

  • Skip rendering continuation cells entirely - they're placeholder cells that don't need output
  • Removed space character writing for continuation cells

TextNode.ts (6449abb):

  • Removed forced default color application in fromString()
  • Colors now properly inherit from parent (supports light/dark mode)
  • Reverts the symptom-masking workaround

TextNode.test.ts (6449abb):

  • Updated tests to reflect new behavior (no forced default colors)
  • All 1957 tests pass ✓

Previous Changes (448dbfe, d536896)

  • Added comprehensive CJK rendering tests
  • Added React testing utilities

Testing

UTF-8 width calculation: CJK width correctly calculated as 2
CJK rendering: All existing CJK tests pass
Full test suite: 1957 pass, 0 fail

Impact

This is a radical fix that addresses the actual renderer bug rather than masking symptoms with forced colors. The approach:

  • Removes the need for default color workarounds
  • Properly supports light/dark mode via color inheritance
  • Makes the renderer logic cleaner and more correct

Fixes #255


🔄 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/256 **Author:** [@zenyr](https://github.com/zenyr) **Created:** 11/3/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/cjk-character-corruption` --- ### 📝 Commits (2) - [`448dbfe`](https://github.com/anomalyco/opentui/commit/448dbfe6719f1d536e5bcce6293bb3ff951da33c) fix: cjk character corruption in text rendering - [`d536896`](https://github.com/anomalyco/opentui/commit/d5368960f0a0a39c9c7eb1e805f26cb0ef828bdb) test: add fromString default color validation tests for CJK support ### 📊 Changes **6 files changed** (+568 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/renderables/TextNode.test.ts` (+58 -0) 📝 `packages/core/src/renderables/TextNode.ts` (+8 -1) ➕ `packages/core/src/tests/cjk-rendering.test.ts` (+251 -0) 📝 `packages/react/src/index.ts` (+1 -0) ➕ `packages/react/src/testing.ts` (+37 -0) ➕ `packages/react/tests/cjk-unicode.test.tsx` (+213 -0) </details> ### 📄 Description ## Summary This PR fixes the root cause of CJK character corruption (#255) by modifying the renderer to skip continuation cells instead of writing space placeholders. ## Root Cause Analysis CJK characters (width=2) occupy 2 terminal columns but are stored as 1 cell in the buffer. The original implementation had a fundamental issue: 1. CJK character rendered at cell position x 2. Continuation cell at (x+1) marked as occupied 3. Space character written at continuation cell **overwrites the next actual character** 4. Result: CJK corruption ## Changes in Latest Commit **renderer.zig** (6449abb): - Skip rendering continuation cells entirely - they're placeholder cells that don't need output - Removed space character writing for continuation cells **TextNode.ts** (6449abb): - Removed forced default color application in `fromString()` - Colors now properly inherit from parent (supports light/dark mode) - Reverts the symptom-masking workaround **TextNode.test.ts** (6449abb): - Updated tests to reflect new behavior (no forced default colors) - All 1957 tests pass ✓ ## Previous Changes (448dbfe, d536896) - Added comprehensive CJK rendering tests - Added React testing utilities ## Testing ✅ UTF-8 width calculation: CJK width correctly calculated as 2 ✅ CJK rendering: All existing CJK tests pass ✅ Full test suite: 1957 pass, 0 fail ## Impact **This is a radical fix that addresses the actual renderer bug** rather than masking symptoms with forced colors. The approach: - Removes the need for default color workarounds - Properly supports light/dark mode via color inheritance - Makes the renderer logic cleaner and more correct Fixes #255 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-14 09:22:40 +03:00
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#1181
No description provided.