added innerhtml linebreaks after every print to console
parent
ffb5050b13
commit
4904e2901c
21
index.html
21
index.html
|
|
@ -37,22 +37,24 @@
|
||||||
|
|
||||||
// Redirect Python's stdout and stderr to the console area
|
// Redirect Python's stdout and stderr to the console area
|
||||||
pyodide.runPython(`
|
pyodide.runPython(`
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
from js import document
|
from js import document
|
||||||
|
|
||||||
class ConsoleOutput:
|
class ConsoleOutput:
|
||||||
def write(self, text):
|
def write(self, text):
|
||||||
console = document.getElementById("console")
|
console = document.getElementById("console")
|
||||||
console.textContent += text
|
|
||||||
|
console.innerHTML += text.replace("\\n", "<br>") # Convert newlines to <br>
|
||||||
console.scrollTop = console.scrollHeight # Auto-scroll to bottom
|
console.scrollTop = console.scrollHeight # Auto-scroll to bottom
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
sys.stdout = ConsoleOutput()
|
sys.stdout = ConsoleOutput()
|
||||||
sys.stderr = ConsoleOutput()
|
sys.stderr = ConsoleOutput()
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
||||||
return pyodide;
|
return pyodide;
|
||||||
}
|
}
|
||||||
|
|
@ -80,8 +82,7 @@
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example usage
|
|
||||||
const input = " Line 1\n Line 2\nLine 3";
|
|
||||||
const output = addExtraLineWithIndent(code, "await asyncio.sleep(0.01)");
|
const output = addExtraLineWithIndent(code, "await asyncio.sleep(0.01)");
|
||||||
console.log(output);
|
console.log(output);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue