FrederickSundeep commited on
Commit
25ebccb
·
1 Parent(s): 878c78c

commit initial 09-12-2025 35

Browse files
Files changed (1) hide show
  1. src/App.js +13 -4
src/App.js CHANGED
@@ -307,14 +307,17 @@ const [interactivePromptShown, setInteractivePromptShown] = useState(false);
307
  setOutput(out);
308
  setProblems(res.error ? parseProblems(res.output) : []);
309
  if (outputLooksForInput(out)) {
310
- // program still waits for more input
311
  setAwaitingInput(true);
312
  focusXtermHelper();
313
  } else {
 
314
  setAwaitingInput(false);
 
315
  }
316
  } catch (err) {
317
  setOutput(String(err));
 
318
  setAwaitingInput(true);
319
  } finally {
320
  setIsRunning(false);
@@ -322,8 +325,9 @@ const [interactivePromptShown, setInteractivePromptShown] = useState(false);
322
  };
323
 
324
 
 
325
  // Initial Run: do NOT run if code needs interactive input and there's no accumulated stdin.
326
- const handleRun = async () => {
327
  const node = getNodeByPath(tree, activePath);
328
  if (!node || node.type !== "file") {
329
  setOutput("Select a file to run.");
@@ -351,7 +355,7 @@ const [interactivePromptShown, setInteractivePromptShown] = useState(false);
351
  // Otherwise run immediately with whichever stdin we have (accumStdin or legacy stdin)
352
  const stdinToSend = accumStdin || stdin || "";
353
 
354
- resetTerminal(false); // keep accumStdin
355
  setOutput(`[Running with stdin length=${stdinToSend ? stdinToSend.length : 0}]\n`);
356
  setIsRunning(true);
357
  setProblems([]);
@@ -360,16 +364,21 @@ const [interactivePromptShown, setInteractivePromptShown] = useState(false);
360
  const out = res.output ?? "";
361
  setOutput(out);
362
  setProblems(res.error ? parseProblems(res.output) : []);
 
363
  if (outputLooksForInput(out)) {
 
364
  setAwaitingInput(true);
365
  focusXtermHelper();
 
366
  } else {
 
367
  setAwaitingInput(false);
368
  setInteractivePromptShown(false);
 
369
  }
370
  } catch (err) {
371
  setOutput(String(err));
372
- // Allow user to type into terminal after EOF errors
373
  setAwaitingInput(true);
374
  setInteractivePromptShown(true);
375
  focusXtermHelper();
 
307
  setOutput(out);
308
  setProblems(res.error ? parseProblems(res.output) : []);
309
  if (outputLooksForInput(out)) {
310
+ // program still waits for more input — keep accumStdin so input can be appended
311
  setAwaitingInput(true);
312
  focusXtermHelper();
313
  } else {
314
+ // program finished — clear accumulated stdin so next Run asks fresh
315
  setAwaitingInput(false);
316
+ setAccumStdin("");
317
  }
318
  } catch (err) {
319
  setOutput(String(err));
320
+ // on error, allow user to continue the interactive session
321
  setAwaitingInput(true);
322
  } finally {
323
  setIsRunning(false);
 
325
  };
326
 
327
 
328
+
329
  // Initial Run: do NOT run if code needs interactive input and there's no accumulated stdin.
330
+ const handleRun = async () => {
331
  const node = getNodeByPath(tree, activePath);
332
  if (!node || node.type !== "file") {
333
  setOutput("Select a file to run.");
 
355
  // Otherwise run immediately with whichever stdin we have (accumStdin or legacy stdin)
356
  const stdinToSend = accumStdin || stdin || "";
357
 
358
+ resetTerminal(true); // keep accumStdin during the run
359
  setOutput(`[Running with stdin length=${stdinToSend ? stdinToSend.length : 0}]\n`);
360
  setIsRunning(true);
361
  setProblems([]);
 
364
  const out = res.output ?? "";
365
  setOutput(out);
366
  setProblems(res.error ? parseProblems(res.output) : []);
367
+
368
  if (outputLooksForInput(out)) {
369
+ // program still waits for more input — keep accumStdin so user can continue
370
  setAwaitingInput(true);
371
  focusXtermHelper();
372
+ setInteractivePromptShown(false); // prompt already consumed / handled
373
  } else {
374
+ // program finished — clear accumulated stdin so next Run asks for fresh input
375
  setAwaitingInput(false);
376
  setInteractivePromptShown(false);
377
+ setAccumStdin("");
378
  }
379
  } catch (err) {
380
  setOutput(String(err));
381
+ // After an exception (like EOF), keep awaitingInput true so user can type
382
  setAwaitingInput(true);
383
  setInteractivePromptShown(true);
384
  focusXtermHelper();