|
1 | 1 | import { constants } from "node:fs"; |
2 | 2 | import { access as fsAccess, readdir as fsReaddir, stat as fsStat } from "node:fs/promises"; |
3 | 3 | import { basename, dirname, isAbsolute, relative, resolve as resolvePath, sep } from "node:path"; |
4 | | -import { Text } from "@earendil-works/pi-tui"; |
5 | 4 | import { hasErrnoCode, toErrorObject } from "../../../infra/errors.js"; |
6 | 5 | import { readRegularFile } from "../../../infra/regular-file.js"; |
7 | 6 | import { decodeWindowsTextFileBuffer } from "../../../infra/windows-encoding.js"; |
@@ -52,6 +51,7 @@ import { |
52 | 51 | getTextOutput, |
53 | 52 | invalidArgText, |
54 | 53 | replaceTabs, |
| 54 | + reuseTextComponent, |
55 | 55 | shortenPath, |
56 | 56 | str, |
57 | 57 | trimTrailingEmptyLines, |
@@ -623,31 +623,25 @@ export function createReadToolDefinition( |
623 | 623 | }); |
624 | 624 | }, |
625 | 625 | renderCall(args, theme, context) { |
626 | | - const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0); |
627 | 626 | const classification = !context.expanded |
628 | 627 | ? getCompactReadClassification(args, context.cwd) |
629 | 628 | : undefined; |
630 | | - text.setText( |
631 | | - classification |
632 | | - ? formatCompactReadCall(classification, args, theme) |
633 | | - : formatReadCall(args, theme), |
634 | | - ); |
635 | | - return text; |
| 629 | + const content = classification |
| 630 | + ? formatCompactReadCall(classification, args, theme) |
| 631 | + : formatReadCall(args, theme); |
| 632 | + return reuseTextComponent(context.lastComponent, content); |
636 | 633 | }, |
637 | 634 | renderResult(result, optionsLocal, theme, context) { |
638 | | - const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0); |
639 | | - text.setText( |
640 | | - formatReadResult( |
641 | | - context.args, |
642 | | - result, |
643 | | - optionsLocal, |
644 | | - theme, |
645 | | - context.showImages, |
646 | | - context.cwd, |
647 | | - context.isError, |
648 | | - ), |
| 635 | + const content = formatReadResult( |
| 636 | + context.args, |
| 637 | + result, |
| 638 | + optionsLocal, |
| 639 | + theme, |
| 640 | + context.showImages, |
| 641 | + context.cwd, |
| 642 | + context.isError, |
649 | 643 | ); |
650 | | - return text; |
| 644 | + return reuseTextComponent(context.lastComponent, content); |
651 | 645 | }, |
652 | 646 | }; |
653 | 647 | } |
|
0 commit comments