forked from makeanedublocksblock/EduBlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
63 lines (51 loc) · 1.21 KB
/
app.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { newServer } from './server';
import { App, TerminalInterface } from './types';
import { getIo } from './io';
import { newSamples } from './samples';
async function newApp(): Promise<App> {
const client = await newServer();
const io = getIo();
const samples = newSamples();
function runCode(code: string) {
return client.runCode(code);
}
function openFile() {
return io.openFile();
}
function saveFile(data: string, ext: string) {
return io.saveFile(data, ext);
}
function assignTerminal(terminal: TerminalInterface) {
client.on('data', (data) => terminal.write(data));
client.on('reconnect', () => {
terminal.reset();
client.resizeTerminal(terminal.cols, terminal.rows);
});
terminal.on('data', client.sendData);
terminal.on('resize', client.resizeTerminal);
if (terminal.cols && terminal.rows) {
client.resizeTerminal(terminal.cols, terminal.rows);
}
}
function getThemes() {
return [
'Default',
'Tangerine',
'DarkRed',
'Celestial',
'Pacific',
'Dark',
];
}
return {
runCode,
openFile,
saveFile,
assignTerminal,
getThemes,
...samples,
};
}
export {
newApp,
};