Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/dash-wasm/src/node-terminal.ts
1067 views
1
/*
2
dash-wasm [--worker] ...
3
*/
4
5
import { asyncDash, syncDash } from "./node";
6
import { supportsPosix } from "@cowasm/kernel";
7
import { Options } from "./common";
8
9
async function main() {
10
const { worker } = processArgs(process.argv);
11
if (process.platform == "win32") {
12
console.log("Press enter a few times.");
13
}
14
const options: Options = { interactive: true }; // todo -- what if not interactive (?)
15
const Dash = worker ? asyncDash : syncDash;
16
const dash = await Dash(options);
17
const argv = process.argv.slice(1);
18
let r = 0;
19
try {
20
// TODO: in async mode the worker thread itself just gets killed... See note about python in python-wasm/src/node-terminal.ts
21
r = await dash.terminal(argv);
22
} catch (_err) {}
23
if (argv.includes("-h")) {
24
console.log(`${process.argv[1]} [--worker] ...`);
25
console.log(
26
"--worker : use a worker thread, instead of single threaded version (NOTE: exit code is always 0)"
27
);
28
}
29
process.exit(r);
30
}
31
32
function processArgs(argv: string[]): { worker: boolean } {
33
const j = argv.indexOf("--worker");
34
if (j != -1) {
35
argv.splice(j, 1);
36
}
37
let worker = false;
38
if (!supportsPosix()) {
39
worker = true;
40
} else {
41
worker = j != -1;
42
}
43
return { worker };
44
}
45
46
main();
47
48