Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions wasm/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@
<head>
<meta charset="utf-8">
<title>RustPython Starter Application</title>
<style type="text/css" media="screen">
#code {
height: 70vh;
width: 95vw;
}

#run-btn {
width: 10em;
height: 5em;
}
</style>
</head>
<body>
<h1>RustPython Demo</h1>
<p>Please input your python code below and click <kbd>Run</kbd>:</p>
<textarea id="code">x = 1
y = 2
print('Hello! x + y equals to ' + str(x+y))
</textarea>
<button id="run-btn">Run</button>
<h2>Open the browser console (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd> or <kbd>F12</kbd>) to see the output</h2>
<script src="./bootstrap.js"></script>
</body>
</html>
12 changes: 11 additions & 1 deletion wasm/app/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import * as rp from "rustpython_wasm";

rp.run_code("print('Hello Python!')\n");
function runCodeFromTextarea(_) {
const code = document.getElementById('code').value;
if (!code.endsWith('\n')) { // HACK: if the code doesn't end with newline it crashes.
rp.run_code(code + '\n');
return;
}
rp.run_code(code);
}
document.getElementById('run-btn').addEventListener('click', runCodeFromTextarea);

runCodeFromTextarea(); // Run once for demo