Skip to content

fix: resolve 4 bugs in termui - #3585

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 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.
  • Removed redundant boolean comparison: x === true is equivalent to x (and x === false to !x), and shorter to read.
  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.

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: #3584

Summary by CodeRabbit

  • Bug Fixes

    • Improved keyboard shortcut handling when clearing forms.
    • Corrected tab navigation parsing for more reliable showcase interactions.
  • Reliability

    • Added clearer error reporting when form-related operations fail, making issues easier to diagnose.

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

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR changes keyboard event handling in two examples and adds rejection logging for a Promise.all operation in the form component.

Changes

Keyboard handling updates

Layer / File(s) Summary
Keyboard handler changes
examples/forms-and-validation/src/index.tsx, examples/showcase/src/index.tsx
The clear-form shortcut now uses event.ctrl !. Tab-key parsing now uses parseInt with radix 10.

Form error logging

Layer / File(s) Summary
Promise rejection logging
packages/ui/src/Form.ts
A .catch handler logs Promise.all failures with console.error.

Estimated code review effort: 2 (Simple) | ~10 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 bug fixes and testing, but it omits the required package section and uses “Ref” instead of the required “Closes #” issue format. Add the required “Which package(s)?” section, change the issue reference to “Closes #3584,” and complete the repository checklist and GSSoC section.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required type prefix and clearly identifies the pull request as a fix for four TermUI bugs.
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 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.6)
packages/ui/src/Form.ts

File contains syntax errors that prevent linting: Line 142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.


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`:
- Line 125: Update the clear-shortcut condition near the key handling logic to
detect plain “c” presses by checking that Ctrl is not active, rather than
applying a non-null assertion to event.ctrl. Preserve the existing earlier
Ctrl+C quit behavior and add an inline comment if a type assertion remains
necessary.

In `@packages/ui/src/Form.ts`:
- Around line 141-142: Remove the detached .catch handler after the Form class
in Form.ts, including the console.error callback, so no standalone promise chain
remains outside the class and the file parses successfully.
🪄 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: 1d8d1f81-628b-4434-828a-2ed311dce364

📥 Commits

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

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

}

if (event.key === 'c' && event.ctrl === false) {
if (event.key === 'c' && event.ctrl !) {

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:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant file and surrounding code without executing repository code.
fd -a 'index\.tsx$' . | sed 's#^\./##' | grep 'examples/forms-and-validation/src/index.tsx' || true

wc -l examples/forms-and-validation/src/index.tsx
sed -n '100,140p' examples/forms-and-validation/src/index.tsx | nl -ba -v100

# Static verifier for the key condition shape and nearby guard around Ctrl+C.
python3 - <<'PY'
from pathlib import Path
p = Path('examples/forms-and-validation/src/index.tsx')
text = p.read_text()
lines = text.splitlines()
for i in [120, 121, 122, 123, 124, 125]:
    print(f'{i}: {lines[i-1]}')
print('Has Ctrl+C exit guard before line 125:', any('event.ctrlKey' in l or "'Ctrl'" in l or 'event.ctrl' in l and 'exit' in l for l in lines[119:124]))
print('Line 125 contains non-null assertion:', 'event.ctrl !' in lines[124])
PY

# If TypeScript is available in the sandbox, run a read-only semantic probe on the exact postfix expression.
if command -v tsc >/dev/null 2>&1; then
  tmp="$(mktemp -d)"
  cat > "$tmp/probe.ts" <<'TS'
const event = { key: 'c', ctrl: false };
const x = event.ctrl;
const nonNull = x !== undefined && x !== null;
const explicitFalse = event.ctrl === false;
const sameLiteral = event.ctrl ! === event.ctrl;
console.log(JSON.stringify({
  typeChecked: true,
  controlLiteralEqualsFalse: event.ctrl === false,
  nonNullPredicateForBooleanFalse: nonNull,
  explicitFalsePredicateForBooleanFalse: explicitFalse,
  sameLiteralBehaviorForBooleanFalse: sameLiteral,
}));
TF;
  tsc --strict "$tmp/probe.ts" --noEmit
else
  echo "TypeScript compiler not available; semantic probe skipped."
fi

Repository: Karanjot786/TermUI

Length of output: 307


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- surrounding code ---"
sed -n '110,135p' examples/forms-and-validation/src/index.tsx

echo
echo "--- static verifier ---"
python3 <<'PY'
from pathlib import Path
p = Path('examples/forms-and-validation/src/index.tsx')
lines = p.read_text().splitlines()
for i in range(119, 126):
    print(f'{i+1}: {lines[i]}')
print('\nLine 125 contains non-null assertion:', 'event.ctrl !' in lines[124])
print('Ctrl+C / Ctrl key references around guard:', [lines[i].strip() for i in range(119, 126) if 'ctrl' in lines[i].lower() or 'key' in lines[i].lower()])
PY

echo
echo "--- TypeScript semantic probe if available ---"
if command -v tsc >/dev/null 2>&1; then
  tmp="$(mktemp -d)"
  cat > "$tmp/probe.ts" <<'TS'
const event = { key: 'c', ctrl: false };
const value = event.ctrl;
const nonNullCondition = value !== undefined && value !== null;
const explicitFalseCondition = event.ctrl === false;
const literalSameAsControl = event.ctrl ! === event.ctrl;
console.log(JSON.stringify({
  controlLiteralEqualsFalse: event.ctrl === false,
  nonNullPredicateForBooleanFalse: nonNullCondition,
  explicitFalsePredicateForBooleanFalse: explicitFalseCondition,
  sameLiteralBehaviorForBooleanFalse: literalSameAsControl,
}));
TS
  tsc --strict "$tmp/probe.ts" --noEmit
else
  echo "tsc not available"
fi

Repository: Karanjot786/TermUI

Length of output: 2792


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- KeyEvent definition/usages ---"
rg -n "interface KeyEvent|class KeyEvent|type KeyEvent|export .*KeyEvent|ctrl\b" examples/forms-and-validation -S

echo
echo "--- corrected TypeScript semantic probe ---"
if command -v tsc >/dev/null 2>&1; then
  tmp="$(mktemp -d)"
  cat > "$tmp/probe.ts" <<'TS'
interface KeyEvent {
  key: string;
  ctrl: boolean;
}

const plainC: KeyEvent = { key: 'c', ctrl: false };
const value = plainC.ctrl;
const nonNullCondition = value !== undefined && value !== null;
const explicitFalseCondition = plainC.ctrl === false;
const literalSameAsControl = plainC.ctrl ! === plainC.ctrl;

console.log(JSON.stringify({
  controlLiteralEqualsFalse: plainC.ctrl === false,
  nonNullPredicateForBooleanFalse: nonNullCondition,
  explicitFalsePredicateForBooleanFalse: explicitFalseCondition,
  sameLiteralBehaviorForBooleanFalse: literalSameAsControl,
}));
TS
  tsc --strict "$tmp/probe.ts" --noEmit
fi

Repository: Karanjot786/TermUI

Length of output: 687


Restore the no-Ctrl clear shortcut.

event.ctrl ! is a non-null assertion. It does not negate event.ctrl. Plain c fails this condition. Ctrl+C quits at lines 121-122 before the clear shortcut is reached.

Proposed fix
-        if (event.key === 'c' && event.ctrl !) {
+        if (event.key === 'c' && event.ctrl === false) {

Type assertions must include an inline comment explaining why.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (event.key === 'c' && event.ctrl !) {
if (event.key === 'c' && event.ctrl === 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` at line 125, Update the
clear-shortcut condition near the key handling logic to detect plain “c” presses
by checking that Ctrl is not active, rather than applying a non-null assertion
to event.ctrl. Preserve the existing earlier Ctrl+C quit behavior and add an
inline comment if a type assertion remains necessary.

Source: Coding guidelines

Comment thread packages/ui/src/Form.ts
Comment on lines +141 to +142

.catch(err => console.error("Promise.all failed:", err)); No newline at end of file

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 | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate Form.ts =="
fd -a 'Form\.ts$' . || true

echo "== git status/stat =="
git diff --stat || true

echo "== packages/ui/src/Form.ts outline/size =="
wc -l packages/ui/src/Form.ts
ast-grep outline packages/ui/src/Form.ts 2>/dev/null || true

echo "== relevant Form.ts sections =="
sed -n '1,180p' packages/ui/src/Form.ts

echo "== syntax check with TypeScript if available =="
if command -v tsc >/dev/null 2>&1; then
  tsc --noEmit --strict packages/ui/src/Form.ts 2>&1 | head -60 || true
else
  echo "tsc not available"
fi

Repository: Karanjot786/TermUI

Length of output: 7756


Remove the detached .catch after Form.ts.

Line 142 is outside the Form class and creates a TypeScript parse error, so the package cannot build.

🧰 Tools
🪛 Biome (2.5.6)

[error] 142-142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.

(parse)

🤖 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/Form.ts` around lines 141 - 142, Remove the detached .catch
handler after the Form class in Form.ts, including the console.error callback,
so no standalone promise chain remains outside the class and the file parses
successfully.

Source: Linters/SAST tools

@saurabhhhcodes saurabhhhcodes mentioned this pull request Aug 6, 2026
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 6, 2026
4 tasks
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