-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (32 loc) · 1.32 KB
/
index.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
import * as wasm from "erg-playground";
var playground = wasm.Playground.new();
const ascii_art = `
█▀▀ █▀█ █▀▀ █▀█ █ ▄▀█ █▄█ █▀▀ █▀█ █▀█ █ █ █▄ █ █▀▄
██▄ █▀▄ █▄█ █▀▀ █▄▄ █▀█ █ █▄█ █▀▄ █▄█ █▄█ █ ▀█ █▄▀
`;
const additional = `
Web-IDE is here: https://erg-lang.org/web-ide/
`;
const settings = {
prompt: ">>> ",
greetings: ascii_art + additional + playground.start_message() + "\n",
};
const action = function(command, term) {
playground.set_stdout((data) => term.echo(data));
let result = playground.eval(command);
if (result.startsWith("<<CompileError>>")) {
result = result.replace("<<CompileError>>", "");
// TODO: multiline error messages
result = result.replace("1 | ", `1 | ${command}`);
term.echo(result);
} else if (result.startsWith("<<RuntimeError>>")) {
result = result.replace("<<RuntimeError>>", "").split("\n");
let code = result[0];
result = result.slice(1).join("\n");
term.error(`error:\n${code}`);
term.error(result);
} else if (result.length > 0) {
term.echo(result);
}
};
$('body').terminal(action, settings);