all repos — sz-chrome-remote-cdp @ f73941cbca4a2d765b140d474ab4e05e1008d93f

pi-browser-harness, patched to drive a Chrome on another host over CDP, with castle_cdp_search web search

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>
Aman Kumar 145339995+amankumarsingh77@users.noreply.github.com
Tue, 05 May 2026 00:52:11 +0530
commit

f73941cbca4a2d765b140d474ab4e05e1008d93f

parent

71da8e0719c50d9b11c918b032b9ed4d77aabf5b

1 files changed, 13 insertions(+), 2 deletions(-)

jump to
M src/domains/screenshot.ts → 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 @@ const mimeType = details?.format === "jpeg" ? "image/jpeg" : "image/png";

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); }