Skip to content

Commit 70d4a17

Browse files
committed
WASM REPL: run prettier on index.html
1 parent faf2ba4 commit 70d4a17

1 file changed

Lines changed: 77 additions & 63 deletions

File tree

Tools/wasm/emscripten/web_example/index.html

Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
margin: 0 auto;
2121
}
2222
#editor {
23-
padding:5px;
23+
padding: 5px;
2424
border: 1px solid black;
2525
width: 100%;
2626
height: 300px;
@@ -139,7 +139,7 @@
139139

140140
class WasmTerminal {
141141
constructor() {
142-
this.reset()
142+
this.reset();
143143

144144
this.xterm = new Terminal({
145145
scrollback: 10000,
@@ -158,7 +158,7 @@
158158
this.xterm.onData(this.handleTermData);
159159
}
160160

161-
reset(){
161+
reset() {
162162
this.inputBuffer = new BufferQueue();
163163
this.input = "";
164164
this.resolveInput = null;
@@ -203,29 +203,29 @@
203203
if (!(ord === 0x1b || ord == 0x7f || ord < 32)) {
204204
this.inputBuffer.addData(data);
205205
}
206-
// TODO: Handle more escape sequences?
206+
// TODO: Handle more escape sequences?
207207
} else if (ord === 0x1b) {
208208
// Handle special characters
209-
switch(data.slice(1)){
210-
case '[A': // up
209+
switch (data.slice(1)) {
210+
case "[A": // up
211211
this.historyBack();
212212
break;
213-
case '[B': // down
213+
case "[B": // down
214214
this.historyForward();
215215
break;
216-
case '[C': // right
216+
case "[C": // right
217217
this.cursorRight();
218218
break;
219-
case '[D': // left
219+
case "[D": // left
220220
this.cursorLeft();
221221
break;
222-
case '[H': // home key
222+
case "[H": // home key
223223
this.cursorHome(true);
224224
break;
225-
case '[F': // end key
225+
case "[F": // end key
226226
this.cursorEnd(true);
227227
break;
228-
case '[3~': // delete key
228+
case "[3~": // delete key
229229
this.deleteAtCursor();
230230
break;
231231
default:
@@ -248,10 +248,12 @@
248248
break;
249249
case "\x03": // CTRL+C
250250
this.input = "";
251-
this.xterm.write("\n")
252-
this.xterm.write('\x1b[' + (this.cursorPosition + 4) + 'D');
251+
this.xterm.write("\n");
252+
this.xterm.write(
253+
"\x1b[" + (this.cursorPosition + 4) + "D",
254+
);
253255
this.cursorPosition = 0;
254-
this.resolveInput("" + '\n');
256+
this.resolveInput("" + "\n");
255257
break;
256258
case "\x09": // TAB
257259
this.handleTab();
@@ -274,8 +276,8 @@
274276
}
275277
};
276278

277-
clearLine(){
278-
this.xterm.write('\x1b[K')
279+
clearLine() {
280+
this.xterm.write("\x1b[K");
279281
}
280282

281283
writeLine(line) {
@@ -286,12 +288,15 @@
286288

287289
handleCursorInsert(data) {
288290
const trailing = this.input.slice(this.cursorPosition);
289-
this.input = this.input.slice(0, this.cursorPosition) + data + trailing;
291+
this.input =
292+
this.input.slice(0, this.cursorPosition) +
293+
data +
294+
trailing;
290295
this.cursorPosition += data.length;
291296
this.xterm.write(data);
292-
if (trailing.length !== 0){
297+
if (trailing.length !== 0) {
293298
this.xterm.write(trailing);
294-
this.xterm.write('\x1b[' + trailing.length + 'D');
299+
this.xterm.write("\x1b[" + trailing.length + "D");
295300
}
296301
this.updateHistory();
297302
}
@@ -303,12 +308,12 @@
303308
const suffix = this.input.slice(this.cursorPosition);
304309
const count = 4 - (this.cursorPosition % 4);
305310
const toAdd = " ".repeat(count);
306-
this.input = prefix + toAdd + suffix
311+
this.input = prefix + toAdd + suffix;
307312
this.cursorHome(false);
308313
this.clearLine();
309314
this.xterm.write(this.input);
310-
if (suffix){
311-
this.xterm.write('\x1b[' + suffix.length + 'D');
315+
if (suffix) {
316+
this.xterm.write("\x1b[" + suffix.length + "D");
312317
}
313318
this.cursorPosition += count;
314319
this.updateHistory(false);
@@ -323,77 +328,85 @@
323328
return;
324329
}
325330
const trailing = this.input.slice(this.cursorPosition);
326-
this.input = this.input.slice(0, this.cursorPosition - 1) + trailing;
331+
this.input =
332+
this.input.slice(0, this.cursorPosition - 1) + trailing;
327333
this.cursorLeft();
328334
this.clearLine();
329-
if (trailing.length !== 0){
335+
if (trailing.length !== 0) {
330336
this.xterm.write(trailing);
331-
this.xterm.write('\x1b[' + trailing.length + 'D');
337+
this.xterm.write("\x1b[" + trailing.length + "D");
332338
}
333339
this.updateHistory();
334340
}
335341

336-
deleteAtCursor(){
337-
if (this.cursorPosition < this.input.length){
338-
const trailing = this.input.slice(this.cursorPosition + 1);
339-
this.input = this.input.slice(0, this.cursorPosition) + trailing;
342+
deleteAtCursor() {
343+
if (this.cursorPosition < this.input.length) {
344+
const trailing = this.input.slice(
345+
this.cursorPosition + 1,
346+
);
347+
this.input =
348+
this.input.slice(0, this.cursorPosition) + trailing;
340349
this.clearLine();
341-
if (trailing.length !== 0){
350+
if (trailing.length !== 0) {
342351
this.xterm.write(trailing);
343-
this.xterm.write('\x1b[' + trailing.length + 'D');
352+
this.xterm.write("\x1b[" + trailing.length + "D");
344353
}
345354
this.updateHistory();
346355
}
347356
}
348357

349-
cursorRight(){
350-
if (this.cursorPosition < this.input.length){
351-
this.cursorPosition += 1;
352-
this.xterm.write('\x1b[C');
353-
}
358+
cursorRight() {
359+
if (this.cursorPosition < this.input.length) {
360+
this.cursorPosition += 1;
361+
this.xterm.write("\x1b[C");
362+
}
354363
}
355364

356-
cursorLeft(){
357-
if (this.cursorPosition > 0){
365+
cursorLeft() {
366+
if (this.cursorPosition > 0) {
358367
this.cursorPosition -= 1;
359-
this.xterm.write('\x1b[D');
368+
this.xterm.write("\x1b[D");
360369
}
361370
}
362371

363372
cursorHome(updatePosition) {
364-
if (this.cursorPosition > 0){
365-
this.xterm.write('\x1b[' + this.cursorPosition + 'D');
373+
if (this.cursorPosition > 0) {
374+
this.xterm.write("\x1b[" + this.cursorPosition + "D");
366375
if (updatePosition) {
367376
this.cursorPosition = 0;
368377
}
369378
}
370379
}
371380

372381
cursorEnd() {
373-
if (this.cursorPosition < this.input.length){
374-
this.xterm.write('\x1b[' + (this.input.length - this.cursorPosition) + 'C');
382+
if (this.cursorPosition < this.input.length) {
383+
this.xterm.write(
384+
"\x1b[" +
385+
(this.input.length - this.cursorPosition) +
386+
"C",
387+
);
375388
this.cursorPosition = this.input.length;
376389
}
377390
}
378391

379-
updateHistory(){
380-
if (this.historyIndex !== -1){
392+
updateHistory() {
393+
if (this.historyIndex !== -1) {
381394
this.historyBuffer[this.historyIndex] = this.input;
382-
}else{
395+
} else {
383396
this.beforeHistoryNav = this.input;
384397
}
385398
}
386399

387-
historyBack(){
388-
if (this.history.length === 0){
400+
historyBack() {
401+
if (this.history.length === 0) {
389402
return;
390-
}else if (this.historyIndex === -1){
403+
} else if (this.historyIndex === -1) {
391404
// we're not currently navigating the history; store
392405
// the current command and then look at the end of our
393406
// history buffer
394407
this.beforeHistoryNav = this.input;
395408
this.historyIndex = this.history.length - 1;
396-
}else if (this.historyIndex > 0){
409+
} else if (this.historyIndex > 0) {
397410
this.historyIndex -= 1;
398411
}
399412
this.input = this.historyBuffer[this.historyIndex];
@@ -403,14 +416,14 @@
403416
this.cursorPosition = this.input.length;
404417
}
405418

406-
historyForward(){
407-
if (this.history.length === 0 || this.historyIndex === -1){
419+
historyForward() {
420+
if (this.history.length === 0 || this.historyIndex === -1) {
408421
// we're not currently navigating the history; NOP.
409422
return;
410-
}else if (this.historyIndex < this.history.length - 1){
423+
} else if (this.historyIndex < this.history.length - 1) {
411424
this.historyIndex += 1;
412425
this.input = this.historyBuffer[this.historyIndex];
413-
}else if (this.historyIndex == this.history.length - 1){
426+
} else if (this.historyIndex == this.history.length - 1) {
414427
// we're coming back from the last history value; reset
415428
// the input to whatever it was when we started going
416429
// through the history
@@ -449,9 +462,10 @@
449462
}
450463
return new Promise((resolve, reject) => {
451464
this.resolveInput = (value) => {
452-
if (value.replace(/\s/g, '').length != 0){
453-
if (this.historyIndex !== -1){
454-
this.historyBuffer[this.historyIndex] = this.history[this.historyIndex];
465+
if (value.replace(/\s/g, "").length != 0) {
466+
if (this.historyIndex !== -1) {
467+
this.historyBuffer[this.historyIndex] =
468+
this.history[this.historyIndex];
455469
}
456470
this.history.push(value.slice(0, -1));
457471
this.historyBuffer.push(value.slice(0, -1));
@@ -594,11 +608,11 @@
594608
finishedCallback,
595609
);
596610
};
597-
var editor;
598-
document.addEventListener('DOMContentLoaded', () => {
599-
editor = ace.edit("editor");
600-
editor.session.setMode("ace/mode/python");
601-
});
611+
var editor;
612+
document.addEventListener("DOMContentLoaded", () => {
613+
editor = ace.edit("editor");
614+
editor.session.setMode("ace/mode/python");
615+
});
602616
</script>
603617
</head>
604618
<body>

0 commit comments

Comments
 (0)