-
Notifications
You must be signed in to change notification settings - Fork 118
/
wasm.html
147 lines (144 loc) · 5.97 KB
/
wasm.html
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html>
<head>
<title>a-Shell, webAssembly execution</title>
<meta charset='utf-8'/>
<meta name="viewport" content="viewport-fit=cover, width=device-width, height=device-height, initial-scale=1, user-scalable=no">
<script src="require.js"></script>
<script src="wasm_withWorker.js"></script>
<style>
html {
height: 100%;
}
body {
position: fixed;
height: 100%;
width: 100%;
overflow: hidden;
top: 0px;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body autocapitalize='none' contenteditable='false' spellcheck='false' autocomplete='off' autocorrect='off'>
<div id='terminal' autofocus='true' autocapitalize='none' contenteditable='false' spellcheck='false' autocomplete='off' autocorrect='off' ></div>
<script>
// functions to deal with executeJavaScript:
function print(printString) {
window.webkit.messageHandlers.aShell.postMessage('print:' + printString);
}
function println(printString) {
window.webkit.messageHandlers.aShell.postMessage('print:' + printString + '\n');
}
function print_error(printString) {
window.webkit.messageHandlers.aShell.postMessage('print_error:' + printString);
}
const jsc = {
// jsc.readFile(filePath: string): string Open the file at filePath as a UTF-8 file, return the string contents to the JS.
readFile: function readFile(path) {
return prompt("jsc\nreadFile\n" + path);
},
// jsc.readFileBase64(filePath: string): string Open the file at filePath as a binary file, return the content encoded using Base64
readFileBase64: function readFileBase64(path) {
return prompt("jsc\nreadFileBase64\n" + path);
},
// jsc.writeFile(filePath: string, content: string): Result Writes content to a UTF-8 file at filePath.
writeFile: function writeFile(path, content) {
var returnValue = prompt("jsc\nwriteFile\n" + path + "\n" + content);
const entries = returnValue.split("\n");
if (Number(entries[0]) == -1) {
throw new Error(entries[1]);
}
return (Number(returnValue));
},
// jsc.writeFileBase64(filePath: string, content: string): Result Writes binary content encoded using Base64 at filePath.
writeFileBase64: function writeFileBase64(path, content) {
var returnValue = prompt("jsc\nwriteFileBase64\n" + path + "\n" + content);
const entries = returnValue.split("\n");
if (Number(entries[0]) == -1) {
throw new Error(entries[1]);
}
return (Number(returnValue));
},
// jsc.listFiles(folderPath: string): string[] Returns a list of the file names in the folder at folderPath.
listFiles: function listFiles(directory) {
var returnValue = prompt("jsc\nlistFiles\n" + directory);
const entries = returnValue.split("\n");
if (entries[0].count == 0) {
throw new Error(entries[1]);
}
return entries;
},
// jsc.isFile(filePath: string): boolean Returns true if there is a file at filePath, false if there is a folder or nothing there.
isFile: function isFile(path) {
var returnValue = Number(prompt("jsc\nisFile\n" + path));
return (returnValue == 1);
},
// jsc.isDirectory(folderPath: string): boolean Returns true if there is a folder at folderPath, false if there is a file or nothing there.
isDirectory: function isDirectory(path) {
var returnValue = Number(prompt("jsc\nisDirectory\n" + path));
return (returnValue == 1);
},
// jsc.makeFolder(folderPath: string): Result Creates a folder at folderPath.
makeFolder: function makeFolder(path) {
var returnValue = prompt("jsc\nmakeFolder\n" + path);
const entries = returnValue.split("\n");
if (Number(entries[0]) == -1) {
throw new Error(entries[1]);
}
return (Number(returnValue));
},
// jsc.deleteFile(filePath: string): Result Deletes the file at filePath.
deleteFile: function deleteFile(path) {
var returnValue = prompt("jsc\ndelete\n" + path);
const entries = returnValue.split("\n");
if (Number(entries[0]) == -1) {
throw new Error(entries[1]);
}
return (Number(returnValue));
},
// jsc.move(pathA: string, pathB: string): Result Moves a file from pathA to pathB.
move: function move(pathA, pathB) {
var returnValue = prompt("jsc\nmove\n" + pathA + "\n" + pathB);
const entries = returnValue.split("\n");
if (Number(entries[0]) == -1) {
throw new Error(entries[1]);
}
return (Number(returnValue));
},
// jsc.copy(pathA: string, pathB: string): Result Creates a copy of the file at pathA and puts it at pathB.
copy: function copy(pathA, pathB) {
var returnValue = prompt("jsc\ncopy\n" + pathA + "\n" + pathB);
const entries = returnValue.split("\n");
if (Number(entries[0]) == -1) {
throw new Error(entries[1]);
}
return (Number(returnValue));
},
// jsc.getFileSize(filePath: string): number Gets the file size of the file at filePath.
getFileSize: function getFileSize(path) {
var returnValue = prompt("jsc\nfileSize\n" + path);
const entries = returnValue.split("\n");
if (Number(entries[0]) < 0) {
throw new Error(entries[1]);
}
return (Number(returnValue));
},
// jsc.system(command: string): executes the command, and returns the return value (usually 0)
system: function system(command) {
return prompt("jsc\nsystem\n" + command);
}
};
// TODO:
//
// Probably not the right API:
// jsc.readFileBytes(filePath: string): number[] Open the file at filePath, return the contents as an array of bytes (i.e. an array of integers, each in [0, 127]).
// jsc.writeFileBytes(filePath: string, content: number[]): Result Writes content as bytes into the file at filePath.
console.log = println
console.error = print_error
window.appdir = (new URL(".", location.href)).href;
window.webkit.messageHandlers.aShell.postMessage('setHomeDir:');
</script>
</body>
</html>