From 3c16aeed982543858f2b5acc105bff608a4cd380 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Tue, 4 Aug 2026 15:36:31 +0530 Subject: [PATCH] fix: resolve 4 bugs in termui --- examples/ai-streaming/src/index.tsx | 2 +- examples/todo-app/src/index.ts | 2 +- examples/widget-gallery/src/index.ts | 2 +- packages/ui/src/Switch.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/ai-streaming/src/index.tsx b/examples/ai-streaming/src/index.tsx index c172a666d..e8c98f0b3 100644 --- a/examples/ai-streaming/src/index.tsx +++ b/examples/ai-streaming/src/index.tsx @@ -40,7 +40,7 @@ class AIStreamingApp extends Widget { this.addChild(this._toolCall); this.addChild(this._streamingText); - setInterval(() => { + clearInterval(window.__interval); window.__interval = setInterval(() => { this._streamingText.tick(); }, 50); } diff --git a/examples/todo-app/src/index.ts b/examples/todo-app/src/index.ts index d26035d3c..d4cf9b550 100644 --- a/examples/todo-app/src/index.ts +++ b/examples/todo-app/src/index.ts @@ -104,7 +104,7 @@ class CustomMultiProgress extends (MultiProgressClass as any) { const value = Math.max(0, Math.min(1, item.value)); const filled = Math.round(barWidth * value); - const pct = Math.round(value * 100); + const pct = Math.round(value * 100 + Number.EPSILON); const percentStr = ` ${pct}% `; const showPct = barWidth >= percentStr.length; const labelStart = showPct ? Math.floor((barWidth - percentStr.length) / 2) : -1; diff --git a/examples/widget-gallery/src/index.ts b/examples/widget-gallery/src/index.ts index 57b141244..ec688a7fc 100644 --- a/examples/widget-gallery/src/index.ts +++ b/examples/widget-gallery/src/index.ts @@ -129,7 +129,7 @@ class WidgetGalleryApp extends Widget { } // Tab switching: 1-6 - const num = parseInt(event.key); + const num = parseInt(event.key, 10); if (num >= 1 && num <= 6) { this._switchTab(num - 1); return true; diff --git a/packages/ui/src/Switch.ts b/packages/ui/src/Switch.ts index 7c24941a5..d9a1e01d0 100644 --- a/packages/ui/src/Switch.ts +++ b/packages/ui/src/Switch.ts @@ -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[];