Skip to content

Commit e7fd930

Browse files
authored
Update index.html
1 parent e4fa130 commit e7fd930

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

docs/index.html

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ <h3>Output:</h3>
4040
let pyodideReady = false;
4141
let pyodide = null;
4242

43+
// Function to load Pyodide
4344
async function loadPyodideAndPackages() {
4445
pyodide = await loadPyodide();
4546
pyodideReady = true;
@@ -48,23 +49,17 @@ <h3>Output:</h3>
4849

4950
loadPyodideAndPackages();
5051

52+
// Function to redirect stdout to output div
53+
function redirectOutput() {
54+
pyodide.runPython(`
55+
import sys
56+
import io
57+
sys.stdout = io.StringIO() # Redirect stdout to capture print statements
58+
`);
59+
}
60+
61+
// Button click handler to run code
5162
document.getElementById("runBtn").addEventListener("click", async () => {
5263
const output = document.getElementById("output");
53-
if (!pyodideReady) {
54-
output.textContent = "⏳ Please wait, Pyodide is still loading...";
55-
return;
56-
}
57-
58-
output.textContent = ""; // clear old output
59-
try {
60-
const code = cm.getValue();
61-
let result = await pyodide.runPythonAsync(code);
62-
output.textContent = result !== undefined ? result.toString() : "✅ Code executed.";
63-
} catch (err) {
64-
output.textContent = `❌ Error:\n${err}`;
65-
}
66-
});
67-
</script>
6864

69-
</body>
70-
</html>
65+
if (!pyodideReady

0 commit comments

Comments
 (0)