-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdio.ts
46 lines (45 loc) · 1.56 KB
/
stdio.ts
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
import config from "./config.ts";
import { global } from "./main.ts";
import retriever from "./retriever.ts";
export const handler = async (line: string) => {
const [cmd, ...args] = line.split(' ');
switch (cmd) {
case "config": switch (args[0]) {
case "set":
{
// Set the desired config based on the prop specified
try {
(config as unknown as { [p: string]: unknown })[args[1]] = typeof args[2] == "undefined" ? args[2] :
JSON.parse(args.slice(2).join(' '));
}
catch (e) {
if (e.name == "SyntaxError") console.error("Value for setting isn't json-compliant");
else console.error(e);
}
}
break;
case "get":
{
const value = (config as unknown as { [p: string]: unknown })[args[1]];
console.log(JSON.stringify(value));
}
break;
} break;
case "retrieve":
{
// Cancel scheduled iteration
clearTimeout(global.nextIteration);
global.nextIteration = NaN;
// Retrieve the next wallpaper
retriever();
} break;
case "exit":
{
Deno.exit(0);
}
default:
{
console.log(`Unknown commmand "${cmd}".`);
} break;
}
}