Download packages/tui/src/util/collapse-tool-output.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 595 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/util/collapse-tool-output.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/tui/src/util/collapse-tool-output.ts
-
curl -L -o collapse-tool-output.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/util/collapse-tool-output.ts
595 Bytes
| export function collapseToolOutput(output: string, maxLines: number, maxChars: number) { | |
| const lines = output.split("\n") | |
| if (lines.length <= maxLines && Array.from(output).length <= maxChars) { | |
| return { output, overflow: false } | |
| } | |
| const preview = lines.slice(0, maxLines).join("\n") | |
| if (Array.from(preview).length > maxChars) { | |
| return { | |
| output: | |
| Array.from(preview) | |
| .slice(0, Math.max(0, maxChars - 1)) | |
| .join("") + "…", | |
| overflow: true, | |
| } | |
| } | |
| return { output: [...lines.slice(0, maxLines), "…"].join("\n"), overflow: true } | |
| } | |