Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/weather/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function fetchWeather() {
}
}

setInterval(fetchWeather, 5000);
clearInterval(window.__interval); window.__interval = setInterval(fetchWeather, 5000);
fetchWeather();

// Gauge does not expose a public setColor() method, so dynamic color
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-server/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DevTools {
renderTimeMs: timeMs,
widgetCount,
lastRenderAt: now,
fps: Math.round(fps * 10) / 10,
fps: Math.round(fps * 10 + Number.EPSILON) / 10,

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 | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

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

node <<'EOF'
for (const fps of [10, 30, 60, 120]) {
    const scaled = fps * 10;
    const current = scaled + Number.EPSILON;
    const scaleAware = scaled + Number.EPSILON * Math.max(1, Math.abs(scaled));

    console.log({
        fps,
        currentChangesValue: current !== scaled,
        scaleAwareChangesValue: scaleAware !== scaled,
    });
}
EOF

Repository: Karanjot786/TermUI

Length of output: 437


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant file around the changed line.
if [ -f packages/dev-server/src/devtools.ts ]; then
  echo "---- packages/dev-server/src/devtools.ts lines 60-95 ----"
  sed -n '60,95p' packages/dev-server/src/devtools.ts | nl -ba -v60
else
  echo "missing packages/dev-server/src/devtools.ts"
  fd -a 'devtools\.ts$' .
fi

echo "---- behavioral probe for intended boundary cases ----"
node - <<'EOF'
function current(fps) {
  return Math.round(fps * 10 + Number.EPSILON) / 10;
}
function scaleAware(fps) {
  const scaledFps = fps * 10;
  return Math.round(
    scaledFps + Number.EPSILON * Math.max(1, Math.abs(scaledFps)),
  ) / 10;
}

const inputs = [
  0.005, 0.015, 0.05,
  1.005, 1.015, 1.05,
  10.005, 10.015, 10.05,
  30.005, 30.015, 30.05,
  60.005, 60.015, 60.05,
  120.05,
  Number.float64FromBits?(0x3fd0000000000000n): undefined,
];
for (const fps of inputs) {
  const scaled = fps * 10;
  if (Number.isNaN(scaled)) continue;
  console.log(JSON.stringify({
    fps,
    rounded: current(fps),
    scaleAwareRounded: scaleAware(fps),
    boundaryNear: fps === Math.round(fps * 10 + Number.EPSILON * Math.max(1, Math.abs(fps * 10))) / 10 + 0,
    scaled: scaled,
    currentChangesScaled: Number.NEXT_UP(scaled) !== scaled,
    maxSafeIntFloor: Math.floor(Number.MAX_SAFE_INTEGER)
  }));
}
EOF

Repository: Karanjot786/TermUI

Length of output: 254


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p = Path("packages/dev-server/src/devtools.ts")
if p.exists():
    lines = p.read_text().splitlines()
    print("---- packages/dev-server/src/devtools.ts lines 60-95 ----")
    for i, line in enumerate(lines[59:95], start=60):
        print(f"{i}\t{line}")
else:
    print("missing packages/dev-server/src/devtools.ts")
PY

echo "---- behavioral probe for intended boundary cases ----"
node - <<'EOF'
function current(fps) {
  return Math.round(fps * 10 + Number.EPSILON) / 10;
}
function scaleAware(fps) {
  const scaledFps = fps * 10;
  return Math.round(
    scaledFps + Number.EPSILON * Math.max(1, Math.abs(scaledFps)),
  ) / 10;
}

const inputs = [
  0.005, 0.015, 0.05,
  1.005, 1.015, 1.05,
  10.005, 10.015, 10.05,
  30.005, 30.015, 30.05,
  60.005, 60.015, 60.05,
  120.05,
];
for (const fps of inputs) {
  const scaled = fps * 10;
  console.log(JSON.stringify({
    fps,
    currentRounded: current(fps),
    scaleAwareRounded: scaleAware(fps),
    scaledFloat: scaled,
    currentChangesScaled: scaled + Number.EPSILON !== scaled,
    scaleAwareChangesScaled: scaled + Number.EPSILON * Math.max(1, Math.abs(scaled)) !== scaled,
  }));
}
EOF

Repository: Karanjot786/TermUI

Length of output: 3982


Scale the epsilon with the rounded FPS value.

At 60 FPS, fps * 10 becomes 600, and Number.EPSILON is far smaller than the spacing of values around 600. This makes the + Number.EPSILON correction ineffective for normal FPS values. Apply the epsilon to the scaled value instead.

🤖 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/dev-server/src/devtools.ts` at line 81, Update the FPS rounding
expression in the devtools FPS calculation so the epsilon is applied relative to
the scaled value before Math.round, rather than adding raw Number.EPSILON to the
original product. Preserve the existing one-decimal output behavior.

memoryMB: Math.round((process.memoryUsage?.().heapUsed ?? 0) / 1024 / 1024 * 10) / 10,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/Switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class Switch extends Widget {
if (width <= 0) return;

const attrs = styleToCellAttrs(this.style);
const knobPos = Math.round(this._animProgress * 2);
const knobPos = Math.round(this._animProgress * 2 + Number.EPSILON);
const transitioning = this._animProgress > 0 && this._animProgress < 1;

let trackChars: string[];
Expand Down
Loading