@@ -2,6 +2,10 @@ import * as c from "yoctocolors";
22 import { writeln } from "../output.ts";
33 import { writePreviewLines } from "../tool-result-shared.ts";
44
5+function truncateOneLine(value: string, max = 100): string {
6+ return value.length > max ? `${value.slice(0, max - 1)}…` : value;
7+}
8+
59 export function renderShellResult(result: unknown): boolean {
610 const r = result as {
711 stdout: string;
@@ -31,61 +35,40 @@ export function renderShellResult(result: unknown): boolean {
3135 const stdoutSingleLine =
3236 stdoutLines === 1 ? (stdoutNormalized.split(/\r?\n/)[0] ?? "") : null;
3337
34- writeln(
35- ` ${badge} ${c.dim(`exit ${r.exitCode} · stdout ${stdoutLines}L · stderr ${stderrLines}L`)}`,
36- );
38+ const parts = [
39+ `exit ${r.exitCode}`,
40+ `stdout ${stdoutLines}L`,
41+ `stderr ${stderrLines}L`,
42+ ];
3743
3844 if (
3945 r.success &&
4046 !r.timedOut &&
4147 stderrLines === 0 &&
42- stdoutSingleLine !== null
48+ stdoutSingleLine !== null &&
49+ stdoutSingleLine.length > 0
4350 ) {
44- const compact =
45- stdoutSingleLine.length > 100
46- ? `${stdoutSingleLine.slice(0, 97)}…`
47- : stdoutSingleLine;
48- if (compact.length > 0) {
49- writeln(` ${c.dim(`stdout: ${compact}`)}`);
50- }
51- return true;
51+ parts.push(`out: ${truncateOneLine(stdoutSingleLine)}`);
5252 }
5353
54- if (!r.success || r.timedOut) {
55- writePreviewLines({
56- label: "stderr",
57- value: r.stderr,
58- lineColor: c.red,
59- maxLines: 6,
60- });
61- writePreviewLines({
62- label: "stdout",
63- value: r.stdout,
64- lineColor: c.dim,
65- maxLines: 4,
66- });
67- return true;
68- }
54+ writeln(` ${badge} ${c.dim(parts.join(" · "))}`);
6955
70- if (stderrLines > 0) {
71- writePreviewLines({
72- label: "stderr",
73- value: r.stderr,
74- lineColor: c.red,
75- maxLines: 4,
76- });
56+ if (r.success && !r.timedOut) {
57+ return true;
7758 }
7859
79- if (stdoutLines > 0 && stdoutLines <= 3) {
80- writePreviewLines({
81- label: "stdout",
82- value: r.stdout,
83- lineColor: c.dim,
84- maxLines: 3,
85- });
86- } else if (stdoutLines > 3) {
87- writeln(` ${c.dim(`stdout omitted (${stdoutLines} lines)`)}`);
88- }
60+ writePreviewLines({
61+ label: "stderr",
62+ value: r.stderr,
63+ lineColor: c.red,
64+ maxLines: 6,
65+ });
66+ writePreviewLines({
67+ label: "stdout",
68+ value: r.stdout,
69+ lineColor: c.dim,
70+ maxLines: 4,
71+ });
8972
9073 return true;
9174 }