Skip to content

fix: resolve 4 bugs in termui - #3704

Closed
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-94032
Closed

fix: resolve 4 bugs in termui#3704
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-94032

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Replaced global isNaN with Number.isNaN: the global version coerces its argument, so isNaN('1') returns false while Number.isNaN is strict.
  • Removed redundant boolean comparison: x === true is equivalent to x (and x === false to !x), and shorter to read.

Type of Change

  • Bug fix (non-breaking change fixing an issue)

How Has This Been Tested?

  • Local manual testing

Checklist

  • My code follows the style guidelines
  • I have performed a self-review

Related Issue

Ref: #3703

Summary by CodeRabbit

  • Bug Fixes
    • Improved calculator handling for expressions beginning with negative numbers.
    • Corrected tab-key navigation in the widget gallery for consistent numeric selection.
    • Updated confirmation prompts to accurately display the default “Yes” option when enabled.

@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:examples Example apps. area:ui @termuijs/ui labels Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR makes three independent one-line fixes. It replaces global numeric validation, adds an explicit decimal radix for tab parsing, and updates confirmation hint selection for truthy defaults.

Changes

Calculator validation

Layer / File(s) Summary
Strict negative-number validation
examples/calculator/src/index.tsx
The initial negative-number check uses Number.isNaN(Number(tokens[1])).

Widget tab parsing

Layer / File(s) Summary
Decimal tab-key parsing
examples/widget-gallery/src/index.ts
Tab selection calls parseInt with an explicit base-10 radix.

Prompt confirmation

Layer / File(s) Summary
Default confirmation hint selection
packages/ui/src/prompts.ts
Truthy defaults display Y/n; explicit false displays y/N; other values display y/n.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies this as a bug fix and states that it resolves four issues in TermUI.
Description check ✅ Passed The description explains the four fixes, identifies the change type, documents manual testing, and references issue #3703.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

🧹 Nitpick comments (1)
packages/ui/src/prompts.ts (1)

72-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression tests for the hint text.

The existing tests in packages/ui/src/prompts.test.ts verify only "y" and "n" results. They do not inspect the question passed to readline, so a regression in this condition could pass unnoticed. Assert Y/n for true, y/N for false, and y/n when default is omitted.

🤖 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/ui/src/prompts.ts` at line 72, Add regression coverage in the
existing prompts tests for the question passed to readline: assert the hint is
“Y/n” when options.default is true, “y/N” when false, and “y/n” when omitted.
Keep the existing “y” and “n” result assertions intact.
🤖 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.

Nitpick comments:
In `@packages/ui/src/prompts.ts`:
- Line 72: Add regression coverage in the existing prompts tests for the
question passed to readline: assert the hint is “Y/n” when options.default is
true, “y/N” when false, and “y/n” when omitted. Keep the existing “y” and “n”
result assertions intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fdc42c0e-035e-49de-b3ff-96751d0adb6c

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and 4b2f6be.

📒 Files selected for processing (3)
  • examples/calculator/src/index.tsx
  • examples/widget-gallery/src/index.ts
  • packages/ui/src/prompts.ts

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

Labels

area:examples Example apps. area:ui @termuijs/ui type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant