Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/dash-wasm/src/common.ts
1067 views
1
/*
2
Code that is the same for both the browser and node.
3
*/
4
5
import { bind_methods } from "./util";
6
import { join } from "path";
7
8
export interface Options {
9
interactive?: boolean;
10
noStdio?: boolean;
11
}
12
13
export function getEnv(prefix: string = "/") {
14
const USR = join(prefix, "usr");
15
16
const ENV = {
17
TERMCAP: join(USR, "share", "termcap"),
18
PYTHONHOME: USR,
19
PATH: join(USR, "bin") + ":.",
20
};
21
22
return { USR, ENV };
23
}
24
25
class DashWasm {
26
public kernel;
27
protected dash_wasm: string;
28
29
constructor(kernel, dash_wasm: string) {
30
this.kernel = kernel;
31
this.dash_wasm = dash_wasm;
32
bind_methods(this);
33
}
34
}
35
36
export class DashWasmSync extends DashWasm {
37
terminal(argv: string[] = []) {
38
try {
39
return this.kernel.exec([this.dash_wasm].concat(argv.slice(1)));
40
} finally {
41
this.kernel.terminate();
42
}
43
}
44
}
45
46
export class DashWasmAsync extends DashWasm {
47
async terminal(argv: string[] = []) {
48
try {
49
return await this.kernel.exec([this.dash_wasm].concat(argv.slice(1)));
50
} finally {
51
this.kernel.terminate();
52
}
53
}
54
}
55
56