Fix markdown streaming duplication by splitting newlines first

- Added string-width library for proper terminal column width calculation
- Fixed wrapLine() to split by newlines before wrapping (like Text component)
- Fixed Loader interval leak by stopping before container removal
- Changed loader message from 'Loading...' to 'Working...'
This commit is contained in:
Mario Zechner 2025-11-11 19:27:58 +01:00
parent 985f955ea0
commit c5083bb7cb
16 changed files with 429 additions and 372 deletions

View file

@ -3,6 +3,7 @@
*/
import type { Terminal } from "./terminal.js";
import { visibleWidth } from "./utils.js";
/**
* Component interface - all components must implement this
@ -21,6 +22,8 @@ export interface Component {
handleInput?(data: string): void;
}
export { visibleWidth };
/**
* Container - a component that contains other components
*/
@ -211,6 +214,9 @@ export class TUI extends Container {
// Render from first changed line to end
for (let i = firstChanged; i < newLines.length; i++) {
if (i > firstChanged) buffer += "\r\n";
if (visibleWidth(newLines[i]) > width) {
throw new Error("Rendered line exceeds terminal width");
}
buffer += newLines[i];
}