fix : added ASCII fallback for Code widget gutter pipe character - #3435
fix : added ASCII fallback for Code widget gutter pipe character#3435tmdeveloper007 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe Code widget now renders ChangesCode widget rendering
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
packages/widgets/src/display/Code.test.tspackages/widgets/src/display/Code.ts
| 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('|'); | ||
| }); |
There was a problem hiding this comment.
🎯 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.tsRepository: 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));
JSRepository: 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));
JSRepository: 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 }); |
There was a problem hiding this comment.
🎯 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.
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.unicodecheck and falls back to the ASCII pipe character|when Unicode is disabled.Changes
packages/widgets/src/display/Code.ts— replaced hardcoded│withcaps.unicode ? '│' : '|'packages/widgets/src/display/Code.test.ts— added test verifying ASCII pipe fallbackRelated Issues
Type of Change
Checklist
Note: Please assign this PR to the
tmdeveloper007account.Summary by CodeRabbit
|fallback for environments that cannot render the Unicode separator.