Implementng playground.
h3rald h3rald@h3rald.com
Sun, 01 Dec 2024 17:14:47 +0100
5 files changed,
33 insertions(+),
5 deletions(-)
A
web/assets/hex-playground.js
@@ -0,0 +1,21 @@
+let stdinBuffer = []; +const inputBox = document.querySelector("article input") +inputBox.addEventListener("keydown", (event) => { + if (event.key === "Enter" && !event.shiftKey) { + event.preventDefault(); + const input = inputBox.value; + inputBox.value = ""; // Clear the textarea + stdinBuffer.push(...input + "\n"); // Add input to the buffer + } +}); + +Module.print = (text) => { + document.querySelector("article section").textContent += text + "\n"; +}; +Module.printErr = (text) => { + document.querySelector("article section").textContent += text + "\n"; +}; +Module.stdin = () => { + return stdinBuffer.length > 0 ? stdinBuffer.shift().charCodeAt(0) : null; +}; +
M
web/assets/styles.css
→
web/assets/styles.css
@@ -64,3 +64,9 @@
li { margin: 0.5rem 0; } + +article section { + height: 40vh; + white-space: pre-wrap; + +}
M
web/contents/play.html
→
web/contents/play.html
@@ -1,7 +1,6 @@
<article> <h2>Playground</h2> - - <blockquote> - Under construction. - </blockquote> + <section></section> + <input type="text" /> </article> +<script src="/assets/hex.js"></script>