all repos — hex @ e1ce2080fc55ce085717e3d7d6016bd65f9d15f4

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
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
Module.pending_fgets = [];
Module.pending_lines = [];
const inputBox = document.querySelector("article input");
const textarea = document.querySelector("article textarea");
const upload = document.getElementById("upload");
const eval = document.getElementById("evaluate");
const outputBox = document.querySelector("article section section");

eval.style.display = "none";
hide.style.display = "none";
textarea.style.display = "none";

Module.print = (text) => {
  outputBox.textContent += text + "\n";
};

Module.printErr = (text) => {
  outputBox.textContent += text + "\n";
};

eval.addEventListener("click", (e) => {
  const data = textarea.value.replace(/^#!.*?\n/, '').replace(/;.*?\n/g, ' ').replace(/#|.*?|#/mg, '').replace(/\n/mg, ' ');
  Module.pending_lines.push(data);
    let resolver = Module.pending_fgets.shift();
    resolver(Module.pending_lines.shift());
    textarea.value = '';
    textarea.style.display = "none";
    eval.style.display = "none";
    upload.style.display = "block";
    hide.style.display = "none";
});

upload.addEventListener("click", () => {
  upload.style.display = "none";
  textarea.style.display = "flex";
  eval.style.display = "block";
  hide.style.display = "block";
});
hide.addEventListener("click", () => {
  textarea.style.display = "none";
  upload.style.display = "block";
  eval.style.display = "none";
  hide.style.display = "none";
});


inputBox.addEventListener("keydown", (e) => {
  if (e.key === "Enter") {
    e.preventDefault();
    Module.pending_lines.push(inputBox.value);
    outputBox.textContent += "> " + inputBox.value + "\n";
    inputBox.value = '';
  }
  if (Module.pending_fgets.length > 0 && Module.pending_lines.length > 0) {
    let resolver = Module.pending_fgets.shift();
    resolver(Module.pending_lines.shift());
  }
});