all repos — hex @ f69d4c8a605f788f89d26efcdf9a39232c8bdbc9

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
 28
 29
 30
 31


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

Module.printErr = (text) => {
  document.querySelector("article section 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 if (e.key.length === 1) {
    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());
  }
});