|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Python Terminal</title> |
|
<style> |
|
|
|
</style> |
|
</head> |
|
<body> |
|
<div class="terminal"> |
|
<div id="output" class="terminal-output">Python Terminal Ready...</div> |
|
<div class="terminal-input"> |
|
<input type="text" id="code-input" placeholder="Enter Python code or !pip install package..." /> |
|
<button onclick="executeCode()">Run</button> |
|
<button onclick="cleanup()">Cleanup</button> |
|
</div> |
|
</div> |
|
<script> |
|
function executeCode() { |
|
const codeInput = document.getElementById("code-input"); |
|
const outputDiv = document.getElementById("output"); |
|
|
|
fetch("/execute", { |
|
method: "POST", |
|
headers: { "Content-Type": "application/json" }, |
|
body: JSON.stringify({ code: codeInput.value }), |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
outputDiv.innerHTML += `\n> ${codeInput.value}\n${data.result}`; |
|
outputDiv.scrollTop = outputDiv.scrollHeight; |
|
codeInput.value = ""; |
|
}) |
|
.catch(error => { |
|
outputDiv.innerHTML += `\nError: ${error}`; |
|
outputDiv.scrollTop = outputDiv.scrollHeight; |
|
}); |
|
} |
|
|
|
function cleanup() { |
|
fetch("/cleanup", { method: "POST" }) |
|
.then(response => response.json()) |
|
.then(data => { |
|
const outputDiv = document.getElementById("output"); |
|
outputDiv.innerHTML += `\n${data.result}`; |
|
outputDiv.scrollTop = outputDiv.scrollHeight; |
|
}); |
|
} |
|
|
|
|
|
window.addEventListener("beforeunload", cleanup); |
|
</script> |
|
</body> |
|
</html> |
|
|