Skip to content

fix : added ASCII fallback for Code widget gutter pipe character - #3435

Open
tmdeveloper007 wants to merge 1 commit into
Karanjot786:mainfrom
tmdeveloper007:fix/code-ascii-fallback
Open

fix : added ASCII fallback for Code widget gutter pipe character#3435
tmdeveloper007 wants to merge 1 commit into
Karanjot786:mainfrom
tmdeveloper007:fix/code-ascii-fallback

Conversation

@tmdeveloper007

@tmdeveloper007 tmdeveloper007 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a bug in the Code widget where the gutter separator always renders the Unicode box-drawing character (U+2502), even when the terminal does not support Unicode. This causes display issues on ASCII-only terminals.

The fix adds a caps.unicode check and falls back to the ASCII pipe character | when Unicode is disabled.

Changes

  • packages/widgets/src/display/Code.ts — replaced hardcoded with caps.unicode ? '│' : '|'
  • packages/widgets/src/display/Code.test.ts — added test verifying ASCII pipe fallback

Related Issues

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Checklist

  • Code follows the existing style
  • Tests added or updated
  • Documentation updated (if applicable)
  • All tests pass locally

Note: Please assign this PR to the tmdeveloper007 account.

Summary by CodeRabbit

  • Bug Fixes
    • Updated code line-number gutters to use a compatible separator based on Unicode support.
    • Added an ASCII | fallback for environments that cannot render the Unicode separator.

@github-actions github-actions Bot added area:widgets @termuijs/widgets type:testing +10 pts. Tests. labels Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Code widget now renders when Unicode support is enabled and | otherwise. Tests mock caps.unicode and verify the ASCII separator.

Changes

Code widget rendering

Layer / File(s) Summary
Capability-based separator and test coverage
packages/widgets/src/display/Code.ts, packages/widgets/src/display/Code.test.ts
The gutter separator now uses `caps.unicode ? '│' : '

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: type:bug

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the ASCII fallback added for the Code widget gutter separator.
Description check ✅ Passed The description explains the bug, implementation, affected files, issue, change type, and testing status.
Linked Issues check ✅ Passed The changes implement issue #3430 by checking caps.unicode, selecting the correct separator, and testing the ASCII fallback.
Out of Scope Changes check ✅ Passed The code changes are limited to the Code widget fallback and its test, with no unrelated refactors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/widgets/src/display/Code.test.ts`:
- Around line 77-85: Update the ASCII-gutter test to override the writable
caps.unicode property with a scoped Object.defineProperty call, preserving its
original descriptor or value and restoring it in a finally block around the test
logic; remove the vi.spyOn getter usage while keeping the existing Code
rendering assertion unchanged.

In `@packages/widgets/src/display/Code.ts`:
- Line 52: Update the gutter assertion in Code.test.ts to match the separator
selected by the display capability, accepting either the Unicode or ASCII
character, or explicitly enable Unicode within that test before asserting. Keep
the existing Code rendering behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fd831b6e-f7b1-4343-b8d6-2768fbb97184

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and 25cced4.

📒 Files selected for processing (2)
  • packages/widgets/src/display/Code.test.ts
  • packages/widgets/src/display/Code.ts

Comment on lines +77 to +85
it('uses ASCII pipe for gutter separator when caps.unicode is false', () => {
vi.spyOn(caps, 'unicode', 'get').mockReturnValue(false);
const code = new Code('hello');
code.updateRect({ x: 0, y: 0, width: 12, height: 4 });
const screen = new Screen(12, 4);
code.render(screen);
// Gutter separator should be '|' in ASCII mode, not '\u2502'
expect(screen.back[1][2].char).toBe('|');
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 4 'unicode\s*:' packages/core/src/terminal/env-caps.ts
rg -n -C 3 "spyOn\(caps, 'unicode', 'get'\)" packages/widgets/src/display/Code.test.ts

Repository: Karanjot786/TermUI

Length of output: 982


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '--- env-caps.ts ---\n'
sed -n '1,120p' packages/core/src/terminal/env-caps.ts
printf '\n--- Code.test.ts relevant section ---\n'
sed -n '1,130p' packages/widgets/src/display/Code.test.ts
printf '\n--- descriptor probe (repository code not executed) ---\n'
node <<'JS'
const obj = { unicode: true };
const descriptor = Object.getOwnPropertyDescriptor(obj, 'unicode') || Object.getPrototypeOf(obj).unicode || {};
try {
  Object.getOwnPropertyDescriptor(obj, 'unicode');
} catch (e) {
  console.log('descriptorError', e && e.message);
}
console.log(JSON.stringify(descriptor, null, 2));
JS

Repository: Karanjot786/TermUI

Length of output: 247


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- env-caps.ts ---'
sed -n '1,120p' packages/core/src/terminal/env-caps.ts
printf '%s\n' ''
printf '%s\n' '--- Code.test.ts relevant section ---'
sed -n '1,130p' packages/widgets/src/display/Code.test.ts
printf '%s\n' ''
printf '%s\n' '--- descriptor probe ---'
node <<'JS'
const obj = { unicode: true };
const descriptor = Object.getOwnPropertyDescriptor(obj, 'unicode');
console.log(JSON.stringify(descriptor, null, 2));
JS

Repository: Karanjot786/TermUI

Length of output: 7173


Fix the caps.unicode mock used for the ASCII-gutter test.

caps.unicode is a writable data property, not a static getter, so the vi.spyOn(caps, 'unicode', 'get') overload does not correctly replace the value Vitest expects for this accessor signature. Use a scoped Object.defineProperty override instead and restore the original value in finally.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widgets/src/display/Code.test.ts` around lines 77 - 85, Update the
ASCII-gutter test to override the writable caps.unicode property with a scoped
Object.defineProperty call, preserving its original descriptor or value and
restoring it in a finally block around the test logic; remove the vi.spyOn
getter usage while keeping the existing Code rendering assertion unchanged.

Source: Learnings

x += lineNumWidth;

screen.setCell(x, y, { char: '│', dim: true });
screen.setCell(x, y, { char: caps.unicode ? '│' : '|', dim: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Make the existing gutter test capability-independent.

This branch correctly renders | when caps.unicode is false. However, packages/widgets/src/display/Code.test.ts, Line 27 still requires . The test suite fails when TERM=dumb or NO_UNICODE disables Unicode support.

Update that assertion to accept the selected separator, or force Unicode explicitly for that test.

Suggested test adjustment
-        expect(screen.back[1][2].char).toBe('\u2502');
+        expect(screen.back[1][2].char).toBe(caps.unicode ? '\u2502' : '|');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widgets/src/display/Code.ts` at line 52, Update the gutter assertion
in Code.test.ts to match the separator selected by the display capability,
accepting either the Unicode or ASCII character, or explicitly enable Unicode
within that test before asserting. Keep the existing Code rendering behavior
unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:widgets @termuijs/widgets type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : Code widget renders Unicode pipe character without ASCII fallback

1 participant