Spaces:
Configuration error
Configuration error
Commit ·
0a3b0ff
1
Parent(s): f949ee8
commit initial 09-12-2025 020
Browse files205 unmodified lines20620720820921021121221321421521621735 unmodified lines253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303205 unmodified lines// When user types into terminal prompt and presses Enter, append that input to accumStdin + "\n",// then re-run the program with updated accumStdin. Repeat until no input cues.const resetTerminal = () => {setTerminalLines([]);setTerminalInput("");setAccumStdin("");setAwaitingInput(false);};const appendTerminal = (text) => {setTerminalLines((prev) => [...prev, text]);35 unmodified lines// 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();setIsRunning(true);setProblems([]);setOutput("");try {// call backend with current accumStdin (empty on first run)const res = await runCode(node.content, selectedLang, accumStdin || stdin || "");const out = res.output ?? "";setOutput(out);appendTerminal(out);setProblems(res.error ? parseProblems(res.output) : []);if (outputLooksForInput(out)) {// program likely wants input: show promptsetAwaitingInput(true);} else {setAwaitingInput(false);}} catch (err) {const e = String(err);setOutput(e);appendTerminal(e);setAwaitingInput(false);} finally {setIsRunning(false);}};// Called when user types input into terminal and presses Enterconst sendTerminalInput = async () => {205 unmodified lines20620720820921021121221321421521621721821922035 unmodified lines256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312205 unmodified lines// When user types into terminal prompt and presses Enter, append that input to accumStdin + "\n",// then re-run the program with updated accumStdin. Repeat until no input cues.const resetTerminal = (keepAccum = false) => {setTerminalLines([]);setTerminalInput("");// only reset accumulated stdin if caller explicitly wants to clear itif (!keepAccum) {setAccumStdin("");}setAwaitingInput(false);};const appendTerminal = (text) => {setTerminalLines((prev) => [...prev, text]);35 unmodified lines// If code likely needs input and accumStdin is empty, ask for initial inputconst needs = codeNeedsInput(node.content, selectedLang);let stdinToSend = accumStdin || stdin || "";if (needs && !stdinToSend) {const userText = window.prompt("This program appears to request console input (e.g. input() / Scanner).\n\nEnter input lines — use Enter for new lines or paste multi-line input. Leave empty to run without input.","");if (userText === null) {// user cancelled prompt -> do nothing (abort run)appendTerminal("[Run cancelled by user]");return;}// normalize any literal "\n" sequences into real newlines (helps users pasting)const prepared = userText.replace(/\\n/g, "\n");stdinToSend = prepared;// set accumStdin state (so subsequent interactive sends append to it)setAccumStdin(prepared);}// start a fresh terminal *but keep accumStdin* because we want to use it during run// pass keepAccum = true to avoid clearing accumStdinresetTerminal(true);appendTerminal(`[Running with stdin length=${stdinToSend ? stdinToSend.length : 0}]`);setIsRunning(true);setProblems([]);setOutput("");try {// IMPORTANT: use local stdinToSend (not state) so the run uses the value right awayconst res = await runCode(node.content, selectedLang, stdinToSend);const out = res.output ?? "";setOutput(out);appendTerminal(out);setProblems(res.error ? parseProblems(res.output) : []);if (outputLooksForInput(out)) {setAwaitingInput(true);} else {setAwaitingInput(false);}} catch (err) {const e = String(err);setOutput(e);appendTerminal(e);setAwaitingInput(false);} finally {setIsRunning(false);}};// Called when user types input into terminal and presses Enterconst sendTerminalInput = async () => {
src/App.js+47-38