Skip to content

fix: resolve 4 bugs in termui - #3601

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Removed redundant boolean comparison: x === true is equivalent to x (and x === false to !x), and shorter to read.
  • 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: #3600

Summary by CodeRabbit

  • Bug Fixes
    • Improved calculator handling of invalid negative-number input.
    • Corrected the forms shortcut so clearing the form requires pressing Ctrl+C.
    • Updated confirmation prompts to display the affirmative default hint for any enabled default value.

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

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change updates calculator NaN validation, changes the form clear shortcut to Ctrl+C, and makes confirmation prompts treat truthy defaults as affirmative.

Changes

Calculator validation

Layer / File(s) Summary
Numeric validation
examples/calculator/src/index.tsx
safeEval uses Number.isNaN(Number(tokens[1])) for negative-number detection.

Form shortcut handling

Layer / File(s) Summary
Clear-form shortcut
examples/forms-and-validation/src/index.tsx
handleKey opens the clear-form modal for Ctrl+C instead of plain c.

Confirmation default hint

Layer / File(s) Summary
Confirmation hint
packages/ui/src/prompts.ts
promptConfirm uses a truthiness check for the default value.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the changes and testing, but it omits required package, GSSoC, checklist, and issue-closing details. Add the required template sections, identify the affected packages, use “Closes #3600,” and complete the repository checklist and GSSoC fields.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, follows the required type format, and accurately describes the bug-fix scope.
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.

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 `@examples/forms-and-validation/src/index.tsx`:
- Around line 125-127: Update the Ctrl+C branch in the widget’s key-event
handler to call this.markDirty() immediately after this.modal.show() and before
returning, ensuring this state-mutating path follows the widget dirty-state
guideline.
- Around line 125-127: Reorder the key handling in the event handler so the
clear-form Ctrl+C condition executes before the quit branch, and update the quit
condition to respond only to q. Preserve the modal display and handled-event
return behavior for Ctrl+C, while ensuring plain c is not treated as clear-form
input.
🪄 Autofix

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: 72e70c7d-88a6-4c4b-9f28-e4da61181c44

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and 09e178e.

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

Comment on lines +125 to 127
if (event.key === 'c' && event.ctrl !) {
this.modal.show();
return 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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Mark the widget dirty after showing the modal.

This branch changes widget state and returns without calling this.markDirty(). Add the call after this.modal.show().

As per coding guidelines: Every state-mutating method on a widget calls this.markDirty().

🤖 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 `@examples/forms-and-validation/src/index.tsx` around lines 125 - 127, Update
the Ctrl+C branch in the widget’s key-event handler to call this.markDirty()
immediately after this.modal.show() and before returning, ensuring this
state-mutating path follows the widget dirty-state guideline.

Source: Coding guidelines


🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Handle Ctrl+C before the quit branch.

Line 121 returns false for Ctrl+C, so execution never reaches this modal branch. Plain c then falls through and is inserted into the active field.

Move the clear-form check before the quit check, and reserve the quit check for q.

Proposed fix
-        if (event.key === 'q' || (event.ctrl && event.key === 'c')) {
-            return false;
-        }
-
-        if (event.key === 'c' && event.ctrl !) {
+        if (event.key === 'c' && event.ctrl) {
             this.modal.show();
             return true;
         }
+
+        if (event.key === 'q') {
+            return false;
+        }
🤖 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 `@examples/forms-and-validation/src/index.tsx` around lines 125 - 127, Reorder
the key handling in the event handler so the clear-form Ctrl+C condition
executes before the quit branch, and update the quit condition to respond only
to q. Preserve the modal display and handled-event return behavior for Ctrl+C,
while ensuring plain c is not treated as clear-form input.

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