Spaces:
Configuration error
Configuration error
Commit ·
f949ee8
1
Parent(s): 921b162
commit initial 09-12-2025 019
Browse files216 unmodified lines21721821922022122222322422522622722822923023123223326 unmodified lines260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300216 unmodified linessetTerminalLines((prev) => [...prev, text]);};const handleRun = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {setOutput("Select a file to run.");return;}const selectedLang = LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id;if (!selectedLang || !RUNNABLE_LANGS.includes(selectedLang)) {setOutput(`⚠️ Run not supported for this file type.`);return;}// clear terminal state and start a fresh runresetTerminal();26 unmodified lines// Called when user types input into terminal and presses Enterconst sendTerminalInput = async () => {if (!awaitingInput) return;const userText = terminalInput;// echo user input in terminalappendTerminal(`> ${userText}`);const newAccum = (accumStdin || "") + userText + "\n";setAccumStdin(newAccum);setTerminalInput("");setIsRunning(true);try {// re-run program with updated stdinconst node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {appendTerminal("No file selected.");setAwaitingInput(false);return;}const selectedLang = LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id;const res = await runCode(node.content, selectedLang, newAccum);const out = res.output ?? "";setOutput(out);appendTerminal(out);setProblems(res.error ? parseProblems(res.output) : []);// detect if program still waitingif (outputLooksForInput(out)) {setAwaitingInput(true);} else {setAwaitingInput(false);}} catch (err) {appendTerminal(String(err));setAwaitingInput(false);} finally {setIsRunning(false);}};// Allow pressing Enter to send inputconst onTerminalKeyDown = (e) => {216 unmodified lines21721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327426 unmodified lines301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342216 unmodified linessetTerminalLines((prev) => [...prev, text]);};// helper: detect input calls in source (python/java/js)function codeNeedsInput(code, langId) {if (!code) return false;try {const c = code.toString();if (langId === "python") {return /\binput\s*\(/i.test(c);}if (langId === "java") {return /\bScanner\s*\(|\bnext(Int|Line|Double|())\b/i.test(c) || /\bSystem\.console\(\)/i.test(c);}if (langId === "javascript") {// node.js stdin reads or prompt usage heuristicsreturn /process\.stdin|readline|prompt\(|window\.prompt/i.test(c);}// fallback: look for common wordsreturn /\binput\b|\bScanner\b|\bnextInt\b|prompt\(/i.test(c);} catch {return false;}}const handleRun = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {setOutput("Select a file to run.");return;}const selectedLang = LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id;if (!selectedLang || !RUNNABLE_LANGS.includes(selectedLang)) {setOutput(`⚠️ Run not supported for this file type.`);return;}// If code likely needs input and accumStdin is empty, ask for initial inputconst needs = codeNeedsInput(node.content, selectedLang);if (needs && !accumStdin) {// collect multi-line input: user can paste multiple lines separated by \nconst userText = window.prompt("This program appears to request console input (e.g. input() / Scanner).\n\nEnter input lines separated by a newline (\\n). Leave empty to run without input.","");if (userText == null) {// user pressed cancel: proceed but warnappendTerminal("[Run cancelled by user]");return;}// userText may contain literal backslash-n if pasted; keep it as-is.// Normalize: if the user typed using Enter, it's already multi-line.const prepared = userText.replace(/\\n/g, "\n");setAccumStdin(prepared);}// clear terminal state and start a fresh runresetTerminal();26 unmodified lines// Called when user types input into terminal and presses Enterconst sendTerminalInput = async () => {if (!currentNode || currentNode.type !== "file") {appendTerminal("No file selected.");setAwaitingInput(false);return;}// If not already in awaitingInput (heuristic missed), still allow sending input:if (!awaitingInput && !isRunning && terminalInput.trim()) {appendTerminal("[Info] Sending input to program (re-run).");}const userText = terminalInput;appendTerminal(`> ${userText}`);const newAccum = (accumStdin || "") + userText + "\n";setAccumStdin(newAccum);setTerminalInput("");setIsRunning(true);try {const selectedLang = LANGUAGE_OPTIONS.find((l) => currentNode.name.endsWith(l.ext))?.id;const res = await runCode(currentNode.content, selectedLang, newAccum);const out = res.output ?? "";setOutput(out);appendTerminal(out);setProblems(res.error ? parseProblems(res.output) : []);if (outputLooksForInput(out)) {setAwaitingInput(true);} else {setAwaitingInput(false);}} catch (err) {appendTerminal(String(err));setAwaitingInput(false);} finally {setIsRunning(false);}};// Allow pressing Enter to send inputconst onTerminalKeyDown = (e) => {
src/App.js+83-41