Spaces:
Running
Running
Commit ·
996fe90
1
Parent(s): 07044b4
commit initial 09-12-2025 30
Browse files- src/App.js +15 -15
src/App.js
CHANGED
|
@@ -109,7 +109,7 @@ function App() {
|
|
| 109 |
LANGUAGE_OPTIONS.find((l) => currentNode?.name?.endsWith(l.ext)) ||
|
| 110 |
LANGUAGE_OPTIONS[0];
|
| 111 |
|
| 112 |
-
// ----------
|
| 113 |
const collectFolderPaths = (node, acc = []) => {
|
| 114 |
if (!node) return acc;
|
| 115 |
if (node.type === "folder") acc.push(node.path || "");
|
|
@@ -122,6 +122,7 @@ function App() {
|
|
| 122 |
const filename = window.prompt("Filename (with extension):", "untitled.js");
|
| 123 |
if (!filename) return;
|
| 124 |
|
|
|
|
| 125 |
const selected = getNodeByPath(tree, activePath);
|
| 126 |
let parentPath = "";
|
| 127 |
if (selected?.type === "folder") parentPath = selected.path;
|
|
@@ -267,7 +268,7 @@ function App() {
|
|
| 267 |
}
|
| 268 |
};
|
| 269 |
|
| 270 |
-
// Initial run —
|
| 271 |
const handleRun = async () => {
|
| 272 |
const node = getNodeByPath(tree, activePath);
|
| 273 |
if (!node || node.type !== "file") {
|
|
@@ -280,27 +281,26 @@ function App() {
|
|
| 280 |
return;
|
| 281 |
}
|
| 282 |
|
| 283 |
-
// If code likely needs input and
|
| 284 |
const needs = codeNeedsInput(node.content, selectedLang);
|
| 285 |
-
|
|
|
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
// Inform user in terminal output and allow them to type in XTerm
|
| 290 |
setOutput("[Interactive program detected — type input directly into the terminal]");
|
| 291 |
setAwaitingInput(true);
|
| 292 |
-
//
|
| 293 |
-
// This may produce EOF errors for some programs; user can then type into the terminal to continue.
|
| 294 |
-
} else {
|
| 295 |
-
// reset terminal output for fresh run but keep accumulated stdin
|
| 296 |
-
resetTerminal(true);
|
| 297 |
-
setOutput(`[Running with stdin length=${stdinToSend ? stdinToSend.length : 0}]\n`);
|
| 298 |
}
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
setIsRunning(true);
|
| 301 |
setProblems([]);
|
| 302 |
try {
|
| 303 |
-
// Use local stdinToSend to avoid setState race
|
| 304 |
const res = await runCode(node.content, selectedLang, stdinToSend);
|
| 305 |
const out = res.output ?? "";
|
| 306 |
setOutput(out);
|
|
@@ -313,7 +313,7 @@ function App() {
|
|
| 313 |
} catch (err) {
|
| 314 |
const e = String(err);
|
| 315 |
setOutput(e);
|
| 316 |
-
//
|
| 317 |
setAwaitingInput(true);
|
| 318 |
} finally {
|
| 319 |
setIsRunning(false);
|
|
|
|
| 109 |
LANGUAGE_OPTIONS.find((l) => currentNode?.name?.endsWith(l.ext)) ||
|
| 110 |
LANGUAGE_OPTIONS[0];
|
| 111 |
|
| 112 |
+
// ---------- TREE helpers ----------
|
| 113 |
const collectFolderPaths = (node, acc = []) => {
|
| 114 |
if (!node) return acc;
|
| 115 |
if (node.type === "folder") acc.push(node.path || "");
|
|
|
|
| 122 |
const filename = window.prompt("Filename (with extension):", "untitled.js");
|
| 123 |
if (!filename) return;
|
| 124 |
|
| 125 |
+
// Determine default parent
|
| 126 |
const selected = getNodeByPath(tree, activePath);
|
| 127 |
let parentPath = "";
|
| 128 |
if (selected?.type === "folder") parentPath = selected.path;
|
|
|
|
| 268 |
}
|
| 269 |
};
|
| 270 |
|
| 271 |
+
// Initial run — DO NOT call run if code needs interactive input and we have no accumStdin.
|
| 272 |
const handleRun = async () => {
|
| 273 |
const node = getNodeByPath(tree, activePath);
|
| 274 |
if (!node || node.type !== "file") {
|
|
|
|
| 281 |
return;
|
| 282 |
}
|
| 283 |
|
| 284 |
+
// If code likely needs input and we have no accumulated stdin, don't run — wait for user input in XTerm.
|
| 285 |
const needs = codeNeedsInput(node.content, selectedLang);
|
| 286 |
+
const haveAccum = !!(accumStdin && accumStdin.length > 0);
|
| 287 |
+
const haveLegacyStdin = !!(stdin && stdin.length > 0);
|
| 288 |
|
| 289 |
+
if (needs && !haveAccum && !haveLegacyStdin) {
|
| 290 |
+
// Show helpful message in terminal and enable awaitingInput so user can type into XTerm.
|
|
|
|
| 291 |
setOutput("[Interactive program detected — type input directly into the terminal]");
|
| 292 |
setAwaitingInput(true);
|
| 293 |
+
return; // <-- important: do NOT run now
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
}
|
| 295 |
|
| 296 |
+
// Otherwise run immediately with whichever stdin we have (accumStdin or legacy stdin)
|
| 297 |
+
const stdinToSend = accumStdin || stdin || "";
|
| 298 |
+
|
| 299 |
+
resetTerminal(true); // keep accumStdin
|
| 300 |
+
setOutput(`[Running with stdin length=${stdinToSend ? stdinToSend.length : 0}]\n`);
|
| 301 |
setIsRunning(true);
|
| 302 |
setProblems([]);
|
| 303 |
try {
|
|
|
|
| 304 |
const res = await runCode(node.content, selectedLang, stdinToSend);
|
| 305 |
const out = res.output ?? "";
|
| 306 |
setOutput(out);
|
|
|
|
| 313 |
} catch (err) {
|
| 314 |
const e = String(err);
|
| 315 |
setOutput(e);
|
| 316 |
+
// Allow user to type into terminal after EOF errors
|
| 317 |
setAwaitingInput(true);
|
| 318 |
} finally {
|
| 319 |
setIsRunning(false);
|