-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.js
More file actions
49 lines (36 loc) · 982 Bytes
/
shell.js
File metadata and controls
49 lines (36 loc) · 982 Bytes
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
#!/usr/bin/env node
import osklang from "./osklang_simple.js";
import prompt_sync from "prompt-sync";
import { readFileSync } from 'fs';
import ascii from 'ascii-art';
const prompt = prompt_sync();
const { font } = ascii;
(async () => {
const rendered = await font("Osklang", 'doom').completed();
console.log(rendered);
const [,,fileName] = process.argv;
if (fileName) {
// execute file
let code;
try {
code = readFileSync(fileName, 'utf8');
} catch(e) {
console.log('Invalid input file');
process.exit(1);
}
const { error } = osklang.evaluate(fileName, code);
if (error) console.log(error);
} else {
// open repl
while (true) {
const input = prompt("> ");
if (input === null) break;
const { output, error } = osklang.evaluate('<stdin>', input, 0);
if (error) {
console.log(error);
continue;
}
console.log(output);
}
}
})();