all repos — hex @ c070ca5e13090819004773fae89119eceb0aa6d4

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

web/assets/hex-playground.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27


Module.pending_fgets = [];
Module.pending_chars = [];
Module.pending_lines = [];
Module.print = (text) => {
  document.querySelector("article section").textContent += text + '\n';
};

const inputBox = document.querySelector("article input");

inputBox.addEventListener("keydown", (e) => {
  if (e.key === 'Enter') {
    e.preventDefault();
    Module.pending_lines.push(Module.pending_chars.join(''));
    Module.pending_chars = [];
    inputBox.value = '';
  } else {
    Module.pending_chars.push(e.key);
  }
  if (Module.pending_fgets.length > 0 && Module.pending_lines.length > 0) {
    let resolver = Module.pending_fgets.shift();
    resolver(Module.pending_lines.shift());
  }
});