Skip to content

Commit 4cfa3f1

Browse files
committed
WASM REPL: use ace editor instead of a plain textbox for code snippet
1 parent 77cc952 commit 4cfa3f1

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Tools/wasm/emscripten/web_example/python.html

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
max-width: 800px;
2020
margin: 0 auto;
2121
}
22-
#code {
22+
#editor {
23+
padding:5px;
24+
border: 1px solid black;
2325
width: 100%;
24-
height: 180px;
26+
height: 300px;
2527
}
2628
#info {
2729
padding-top: 20px;
@@ -42,6 +44,11 @@
4244
crossorigin
4345
integrity="sha384-yYdNmem1ioP5Onm7RpXutin5A8TimLheLNQ6tnMi01/ZpxXdAwIm2t4fJMx1Djs+"
4446
></script>
47+
<script
48+
src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.43.1/ace.js"
49+
crossorigin
50+
integrity="sha512-kmA5vhcxOkZI0ReiKJMGNb8/KKbgbExIlnt6aXuPtl86AgHBEi6OHHOz2wsTazBDGZKxe7fmiE+pIuZJQks4+A=="
51+
></script>
4552
<script type="module">
4653
class WorkerManager {
4754
constructor(
@@ -498,8 +505,6 @@
498505
const stopButton = document.getElementById("stop");
499506
const clearButton = document.getElementById("clear");
500507

501-
const codeBox = document.getElementById("codebox");
502-
503508
window.onload = () => {
504509
const terminal = new WasmTerminal();
505510
terminal.open(document.getElementById("terminal"));
@@ -535,7 +540,7 @@
535540
terminal.clear();
536541
terminal.reset(); // reset the history
537542
programRunning(true);
538-
const code = codeBox.value;
543+
const code = editor.getValue();
539544
pythonWorkerManager.run({
540545
args: ["main.py"],
541546
files: { "main.py": code },
@@ -578,14 +583,15 @@
578583
finishedCallback,
579584
);
580585
};
586+
document.addEventListener('DOMContentLoaded', () => {
587+
editor = ace.edit("editor");
588+
editor.session.setMode("ace/mode/python");
589+
});
581590
</script>
582591
</head>
583592
<body>
584593
<h1>Simple REPL for Python WASM</h1>
585-
<textarea id="codebox" cols="108" rows="16">
586-
print('Welcome to WASM!')
587-
</textarea
588-
>
594+
<div id="editor">print('Welcome to WASM!')</div>
589595
<div class="button-container">
590596
<button id="run" disabled>Run</button>
591597
<button id="repl" disabled>Start REPL</button>

0 commit comments

Comments
 (0)