aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-05-05 00:52:11 +0530
committerGitHub <noreply@github.com>2026-05-05 00:52:11 +0530
commitf73941cbca4a2d765b140d474ab4e05e1008d93f (patch)
tree3c8f4a4017f9cc4884425b17288e3736353fbc6e /src
parent71da8e0719c50d9b11c918b032b9ed4d77aabf5b (diff)
fix: prevent TUI crash when screenshot path overflows terminal width (#2)
The Image text-fallback render does not respect the rendered width, so a long file path can blow past the terminal width and crash the host TUI. Wrap the component to truncate each rendered line with truncateToWidth so it fits the available width. Co-authored-by: amankumarsingh77 <amankumarsingh7702@gmal.com>
Diffstat (limited to 'src')
-rw-r--r--src/domains/screenshot.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/domains/screenshot.ts b/src/domains/screenshot.ts
index 60d4b26..74042be 100644
--- a/src/domains/screenshot.ts
+++ b/src/domains/screenshot.ts
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";
import { writeFile, rename } from "node:fs/promises";
import { Type } from "typebox";
-import { Image, type ImageTheme, Text } from "@mariozechner/pi-tui";
+import { Image, type ImageTheme, Text, truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
import type { BrowserClient } from "../client";
import { type Result, err, ok } from "../util/result";
import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool";
@@ -98,11 +98,22 @@ export const screenshotTool = defineBrowserTool({
const imageTheme: ImageTheme = {
fallbackColor: (str: string) => theme.fg("dim", str),
};
- return new Image(b64, mimeType, imageTheme, {
+ const image = new Image(b64, mimeType, imageTheme, {
maxWidthCells: 80,
maxHeightCells: 24,
filename: filePath,
});
+ // Image's text fallback (when terminal lacks inline-image support) does
+ // not respect the rendered width, so a long file path can blow past the
+ // terminal width and crash the host TUI. Wrap the component to truncate
+ // each rendered line to fit.
+ return {
+ invalidate: () => image.invalidate(),
+ render: (width: number) =>
+ image.render(width).map((line) =>
+ visibleWidth(line) > width ? truncateToWidth(line, width) : line,
+ ),
+ };
} catch {
return new Text(theme.fg("warning", `Screenshot saved: ${filePath}`), 0, 0);
}