Files
neuron/packages/opencode/src/cli/cmd/tui/util/collapse-tool-output.ts
T
opencode-agent[bot] 116a4e33ba chore: generate
2026-05-18 11:06:05 +00:00

20 lines
595 B
TypeScript

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