Skip to content

Commit

Permalink
cap output lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushKun committed May 28, 2024
1 parent 5abe094 commit bda3fa9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion next_app/src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import dynamic from 'next/dynamic';
import { useRouter } from "next/router";
import { dryrun } from "@permaweb/aoconnect";
import { title } from "process";
import { capOutputTo200Lines } from "@/lib/utils";
const Plot = dynamic(
() =>
import('react-plotly.js'),
Expand Down Expand Up @@ -245,7 +246,7 @@ const CodeCell = ({
modeBarButtons: [["zoomIn2d"], ["zoomOut2d"], ["autoScale2d"], ["resetScale2d"], ["pan2d"], ["zoom2d"]],
}} />
</div> : <pre className="w-full text-sm font-btr-code max-h-[250px] min-h-[40px] overflow-scroll p-2 ml-20">
{<Ansi useClasses className="font-btr-code">{`${typeof cell.output == "object" ? JSON.stringify(cell.output, null, 2) : cell.output}`}</Ansi>}
{<Ansi useClasses className="font-btr-code">{`${capOutputTo200Lines(typeof cell.output == "object" ? JSON.stringify(cell.output, null, 2) : cell.output as string)}`}</Ansi>}
</pre>}
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions next_app/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ export function tsToDate(ts: number) {
}

export const stripAnsiCodes = (str: string): string => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");

export const capOutputTo200Lines = (str: string): string => {
// if str is less than 200 lines, return it
// else return the first 100 and last 100 lines
const strString = str.toString();
const lines = strString.split("\n");
if (lines.length <= 200) return str;
return lines.slice(0, 100).join("\n") + "\n\x1b[31m... output has been capped at 200 lines ...\x1b[0m\n" + lines.slice(-100).join("\n");
}

0 comments on commit bda3fa9

Please sign in to comment.