Bulk run
This commit is contained in:
@@ -46,7 +46,6 @@ if (typeof window !== "undefined") {
|
||||
interface EditorProps {
|
||||
initialValue?: string;
|
||||
onChange?: (editor: any, changes: any) => void;
|
||||
onRequestRun?: () => void;
|
||||
onReady?: (editor: any) => void;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,12 @@ import { Button } from "@/components/ui/Button";
|
||||
import { Dropdown } from "@/components/ui/Dropdown";
|
||||
import { Editor } from "@/components/Editor";
|
||||
import { Terminal, TerminalRef } from "@/components/Terminal";
|
||||
import { sendDataToScript, startScript, stopScript } from "@/lib/runner";
|
||||
import {
|
||||
sendDataToScript,
|
||||
startScript,
|
||||
startScriptBulk,
|
||||
stopScript,
|
||||
} from "@/lib/runner";
|
||||
import styles from "@/styles/Playground.module.css";
|
||||
|
||||
const initialCode = `
|
||||
@@ -49,7 +54,7 @@ export default function Playground() {
|
||||
const runDisabled = isScriptRunning || !isEditorReady;
|
||||
const stopDisabled = !isScriptRunning;
|
||||
|
||||
const requestRun = useCallback(async () => {
|
||||
const runHuman = useCallback(async () => {
|
||||
if (resultRef.current) {
|
||||
resultRef.current.value = "";
|
||||
}
|
||||
@@ -94,6 +99,51 @@ export default function Playground() {
|
||||
setIsScriptRunning(false);
|
||||
}, [runDisabled]);
|
||||
|
||||
const runBulk = useCallback(async () => {
|
||||
if (resultRef.current) {
|
||||
resultRef.current.value = "";
|
||||
}
|
||||
|
||||
if (runDisabled || !editorRef.current) return;
|
||||
|
||||
setIsScriptRunning(true);
|
||||
|
||||
try {
|
||||
terminalRef.current?.clear();
|
||||
terminalRef.current?.focus();
|
||||
|
||||
await startScriptBulk(
|
||||
editorRef.current.getValue(),
|
||||
(line: string) => {
|
||||
if (resultRef.current) {
|
||||
let v = resultRef.current.value + line + "\n";
|
||||
if (v.length > 10000) {
|
||||
v = v.substring(v.length - 10000);
|
||||
}
|
||||
resultRef.current.value = v;
|
||||
resultRef.current.scrollTop =
|
||||
resultRef.current.scrollHeight -
|
||||
resultRef.current.clientHeight;
|
||||
}
|
||||
},
|
||||
|
||||
(line: string) => {
|
||||
terminalRef.current?.write(line);
|
||||
}
|
||||
);
|
||||
} catch (ex) {
|
||||
const errorMsg = `\nEXCEPTION: "${ex}"\n`;
|
||||
if (resultRef.current) {
|
||||
resultRef.current.value += errorMsg;
|
||||
}
|
||||
terminalRef.current?.write(
|
||||
"\r\n\x1B[1;31mEXCEPTION:\x1B[0m " + String(ex) + "\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
setIsScriptRunning(false);
|
||||
}, [runDisabled]);
|
||||
|
||||
const stopScriptHandler = useCallback(() => {
|
||||
stopScript();
|
||||
}, []);
|
||||
@@ -106,9 +156,7 @@ export default function Playground() {
|
||||
<Button
|
||||
variant="success"
|
||||
iconLeft="play"
|
||||
onClick={() => {
|
||||
requestRun();
|
||||
}}
|
||||
onClick={runHuman}
|
||||
loading={isScriptRunning}
|
||||
disabled={runDisabled}
|
||||
>
|
||||
@@ -118,9 +166,7 @@ export default function Playground() {
|
||||
<Button
|
||||
variant="success"
|
||||
iconLeft="play"
|
||||
onClick={() => {
|
||||
requestRun();
|
||||
}}
|
||||
onClick={runBulk}
|
||||
loading={isScriptRunning}
|
||||
disabled={runDisabled}
|
||||
>
|
||||
@@ -201,12 +247,6 @@ export default function Playground() {
|
||||
ref={editorRef}
|
||||
initialValue={initialCode}
|
||||
onChange={() => {}}
|
||||
onRequestRun={() => {
|
||||
if (resultRef.current) {
|
||||
resultRef.current.value = "";
|
||||
}
|
||||
requestRun();
|
||||
}}
|
||||
onReady={() => setIsEditorReady(true)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user