brsh 3.10.0 → 3.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/shell.es.js +750 -596
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +23 -23
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +3 -3
- package/dist/terminal.cjs.js.map +1 -1
- package/dist/terminal.es.js +55 -33
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +3 -3
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +862 -670
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +14 -14
- package/dist/wbt.min.js.map +1 -1
- package/index.js +79 -18
- package/lib/BaseFileSystem.js +2 -0
- package/lib/BinaryContainer.js +1 -1
- package/lib/Command.js +1 -1
- package/lib/Context.js +3 -2
- package/lib/InteractiveCommand.js +9 -8
- package/lib/ScriptCommand.js +76 -27
- package/lib/Terminal.js +60 -6
- package/lib/TtyStream.js +36 -2
- package/lib/WasmCommand.js +229 -42
- package/lib/wbt/index.js +172 -58
- package/package.json +1 -1
- package/test/devices-signals.test.js +112 -0
- package/test/doom.test.js +7 -4
- package/test/scripts.test.js +48 -0
- package/test/shell.test.js +60 -0
- package/test/terminal.test.js +148 -0
- package/test/wasm-cli.test.js +76 -0
- package/test/wbt.test.js +111 -1
package/lib/WasmCommand.js
CHANGED
|
@@ -8,6 +8,7 @@ const ERRNO_SUCCESS = 0;
|
|
|
8
8
|
const ERRNO_AGAIN = 6;
|
|
9
9
|
const ERRNO_BADF = 8;
|
|
10
10
|
const ERRNO_EXIST = 20;
|
|
11
|
+
const ERRNO_INTR = 27;
|
|
11
12
|
const ERRNO_INVAL = 28;
|
|
12
13
|
const ERRNO_ISDIR = 31;
|
|
13
14
|
const ERRNO_NOENT = 44;
|
|
@@ -107,7 +108,7 @@ class WasmCommand extends ScriptCommand {
|
|
|
107
108
|
this.stdinStream.setRawMode(false);
|
|
108
109
|
}
|
|
109
110
|
if (this.stdout && typeof this.stdout.write === 'function') {
|
|
110
|
-
this.stdout.write('\x1b[?1049l\x1b[?25h');
|
|
111
|
+
this.stdout.write('\x1b[0m\x1b[?1l\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?1049l\x1b[?25h');
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
|
|
@@ -117,6 +118,9 @@ class WasmCommand extends ScriptCommand {
|
|
|
117
118
|
if (key instanceof Uint8Array) return key;
|
|
118
119
|
return new Uint8Array([Number(key) & 0xff]);
|
|
119
120
|
}
|
|
121
|
+
if (['Control', 'Alt', 'Shift', 'Meta', 'CapsLock', 'NumLock', 'ScrollLock', 'Dead', 'Unidentified'].includes(key)) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
120
124
|
const ctrlMatch = key.match(/^\^([A-Za-z@\[\\\]^_?])$/);
|
|
121
125
|
if (ctrlMatch) {
|
|
122
126
|
const ch = ctrlMatch[1].toUpperCase();
|
|
@@ -126,19 +130,40 @@ class WasmCommand extends ScriptCommand {
|
|
|
126
130
|
const map = {
|
|
127
131
|
'Enter': '\r',
|
|
128
132
|
'Return': '\r',
|
|
133
|
+
'Space': ' ',
|
|
134
|
+
'Spacebar': ' ',
|
|
129
135
|
'Backspace': '\x7f',
|
|
130
136
|
'Tab': '\t',
|
|
137
|
+
'BackTab': '\x1b[Z',
|
|
131
138
|
'Escape': '\x1b',
|
|
139
|
+
'Esc': '\x1b',
|
|
132
140
|
'ArrowUp': '\x1b[A',
|
|
141
|
+
'Up': '\x1b[A',
|
|
133
142
|
'ArrowDown': '\x1b[B',
|
|
143
|
+
'Down': '\x1b[B',
|
|
134
144
|
'ArrowRight': '\x1b[C',
|
|
145
|
+
'Right': '\x1b[C',
|
|
135
146
|
'ArrowLeft': '\x1b[D',
|
|
147
|
+
'Left': '\x1b[D',
|
|
136
148
|
'Home': '\x1b[H',
|
|
137
149
|
'End': '\x1b[F',
|
|
138
150
|
'PageUp': '\x1b[5~',
|
|
139
151
|
'PageDown': '\x1b[6~',
|
|
140
152
|
'Delete': '\x1b[3~',
|
|
153
|
+
'Del': '\x1b[3~',
|
|
141
154
|
'Insert': '\x1b[2~',
|
|
155
|
+
'F1': '\x1bOP',
|
|
156
|
+
'F2': '\x1bOQ',
|
|
157
|
+
'F3': '\x1bOR',
|
|
158
|
+
'F4': '\x1bOS',
|
|
159
|
+
'F5': '\x1b[15~',
|
|
160
|
+
'F6': '\x1b[17~',
|
|
161
|
+
'F7': '\x1b[18~',
|
|
162
|
+
'F8': '\x1b[19~',
|
|
163
|
+
'F9': '\x1b[20~',
|
|
164
|
+
'F10': '\x1b[21~',
|
|
165
|
+
'F11': '\x1b[23~',
|
|
166
|
+
'F12': '\x1b[24~',
|
|
142
167
|
};
|
|
143
168
|
if (map[key]) return new TextEncoder().encode(map[key]);
|
|
144
169
|
return new TextEncoder().encode(key);
|
|
@@ -277,7 +302,12 @@ class WasmCommand extends ScriptCommand {
|
|
|
277
302
|
let asyncifyDataAddr = 0;
|
|
278
303
|
let asyncifyPromise = null;
|
|
279
304
|
let pendingReadResolve = null;
|
|
280
|
-
let
|
|
305
|
+
let pendingResizeInterrupt = null;
|
|
306
|
+
let pollTimedOut = false;
|
|
307
|
+
let pollInterrupted = false;
|
|
308
|
+
let readInterrupted = false;
|
|
309
|
+
let onStdoutResize = null;
|
|
310
|
+
let onStdinResize = null;
|
|
281
311
|
let onStreamData = null;
|
|
282
312
|
|
|
283
313
|
const isTtyEnvironment = (this.stdin === undefined || this.stdin === null || this.stdin === this.stdinStream || (this.stdin && this.stdin.isTTY));
|
|
@@ -387,7 +417,13 @@ class WasmCommand extends ScriptCommand {
|
|
|
387
417
|
if (b) enqueueBytes(b);
|
|
388
418
|
};
|
|
389
419
|
|
|
390
|
-
|
|
420
|
+
const hadDefaultStdinListener = Boolean(
|
|
421
|
+
this._onStdinStreamData
|
|
422
|
+
&& this.stdinStream
|
|
423
|
+
&& typeof this.stdinStream.listeners === 'function'
|
|
424
|
+
&& this.stdinStream.listeners('data').includes(this._onStdinStreamData)
|
|
425
|
+
);
|
|
426
|
+
if (hadDefaultStdinListener && typeof this.stdinStream.off === 'function') {
|
|
391
427
|
this.stdinStream.off('data', this._onStdinStreamData);
|
|
392
428
|
}
|
|
393
429
|
if (isTtyEnvironment && this.stdinStream && typeof this.stdinStream.on === 'function') {
|
|
@@ -483,13 +519,21 @@ class WasmCommand extends ScriptCommand {
|
|
|
483
519
|
}
|
|
484
520
|
};
|
|
485
521
|
|
|
486
|
-
// Environment variables from context.vars with terminal
|
|
522
|
+
// Environment variables from context.vars with live terminal dimensions taking precedence
|
|
523
|
+
const initCols = (this.stdout && this.stdout.columns)
|
|
524
|
+
|| (this.stdinStream && this.stdinStream.columns)
|
|
525
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('COLUMNS'), 10))
|
|
526
|
+
|| 80;
|
|
527
|
+
const initRows = (this.stdout && this.stdout.rows)
|
|
528
|
+
|| (this.stdinStream && this.stdinStream.rows)
|
|
529
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('LINES'), 10))
|
|
530
|
+
|| 24;
|
|
487
531
|
const termVars = {
|
|
488
532
|
TERM: 'xterm-256color',
|
|
489
533
|
COLORTERM: 'truecolor',
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
534
|
+
...((this.context && this.context.vars) || {}),
|
|
535
|
+
COLUMNS: String(initCols),
|
|
536
|
+
LINES: String(initRows)
|
|
493
537
|
};
|
|
494
538
|
const envPairs = Object.entries(termVars).map(([k, v]) => `${k}=${v}`);
|
|
495
539
|
|
|
@@ -580,6 +624,12 @@ class WasmCommand extends ScriptCommand {
|
|
|
580
624
|
|
|
581
625
|
if (state === 2) {
|
|
582
626
|
instance.exports.asyncify_stop_rewind();
|
|
627
|
+
if (readInterrupted && inputQueue.length === 0) {
|
|
628
|
+
readInterrupted = false;
|
|
629
|
+
view.setUint32(nread_ptr, 0, true);
|
|
630
|
+
return ERRNO_INTR;
|
|
631
|
+
}
|
|
632
|
+
readInterrupted = false;
|
|
583
633
|
let total = 0;
|
|
584
634
|
for (let i = 0; i < iovs_len && inputQueue.length > 0; i++) {
|
|
585
635
|
const ptr = view.getUint32(iovs + i * 8, true);
|
|
@@ -612,10 +662,27 @@ class WasmCommand extends ScriptCommand {
|
|
|
612
662
|
return ERRNO_AGAIN;
|
|
613
663
|
}
|
|
614
664
|
|
|
665
|
+
readInterrupted = false;
|
|
615
666
|
instance.exports.asyncify_start_unwind(asyncifyDataAddr);
|
|
616
667
|
asyncifyPromise = new Promise((resolve, reject) => {
|
|
617
|
-
|
|
618
|
-
|
|
668
|
+
const onReadReady = () => {
|
|
669
|
+
readInterrupted = false;
|
|
670
|
+
pendingReadResolve = null;
|
|
671
|
+
pendingResizeInterrupt = null;
|
|
672
|
+
this._pendingReadResolve = null;
|
|
673
|
+
this._asyncifyReject = null;
|
|
674
|
+
resolve();
|
|
675
|
+
};
|
|
676
|
+
pendingReadResolve = onReadReady;
|
|
677
|
+
this._pendingReadResolve = onReadReady;
|
|
678
|
+
pendingResizeInterrupt = () => {
|
|
679
|
+
readInterrupted = true;
|
|
680
|
+
pendingReadResolve = null;
|
|
681
|
+
pendingResizeInterrupt = null;
|
|
682
|
+
this._pendingReadResolve = null;
|
|
683
|
+
this._asyncifyReject = null;
|
|
684
|
+
resolve();
|
|
685
|
+
};
|
|
619
686
|
this._asyncifyReject = reject;
|
|
620
687
|
});
|
|
621
688
|
view.setUint32(nread_ptr, 0, true);
|
|
@@ -1064,7 +1131,9 @@ class WasmCommand extends ScriptCommand {
|
|
|
1064
1131
|
},
|
|
1065
1132
|
clock_time_get: (id, prec, time_ptr) => {
|
|
1066
1133
|
if (memRef) {
|
|
1067
|
-
const ns =
|
|
1134
|
+
const ns = (id === 1 && typeof performance !== 'undefined' && typeof performance.now === 'function')
|
|
1135
|
+
? BigInt(Math.round(performance.now() * 1e6))
|
|
1136
|
+
: BigInt(Date.now()) * 1_000_000n;
|
|
1068
1137
|
new DataView(memRef.buffer).setBigUint64(time_ptr, ns, true);
|
|
1069
1138
|
}
|
|
1070
1139
|
return ERRNO_SUCCESS;
|
|
@@ -1115,28 +1184,50 @@ class WasmCommand extends ScriptCommand {
|
|
|
1115
1184
|
|
|
1116
1185
|
if (state === 2) {
|
|
1117
1186
|
instance.exports.asyncify_stop_rewind();
|
|
1187
|
+
if (pollInterrupted && inputQueue.length === 0) {
|
|
1188
|
+
pollInterrupted = false;
|
|
1189
|
+
view.setUint32(nevents_ptr, 0, true);
|
|
1190
|
+
return ERRNO_INTR;
|
|
1191
|
+
}
|
|
1192
|
+
pollInterrupted = false;
|
|
1118
1193
|
let nevents = 0;
|
|
1119
1194
|
for (let i = 0; i < nsubscriptions; i++) {
|
|
1120
1195
|
const subPtr = in_ptr + i * 48;
|
|
1121
1196
|
const userdata = view.getBigUint64(subPtr, true);
|
|
1122
1197
|
const type = view.getUint8(subPtr + 8);
|
|
1123
|
-
|
|
1198
|
+
let isReady = false;
|
|
1124
1199
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1200
|
+
if (type === 0) { // EVENTTYPE_CLOCK
|
|
1201
|
+
isReady = pollTimedOut;
|
|
1202
|
+
} else if (type === 1) { // EVENTTYPE_FD_READ
|
|
1203
|
+
const fd = view.getUint32(subPtr + 16, true);
|
|
1204
|
+
const entry = fdTable.get(fd);
|
|
1205
|
+
const isDevTty = Boolean(entry && entry.type === 'dev_tty');
|
|
1206
|
+
if ((fd === 0 || (isInteractive && fd === 2) || isDevTty) && inputQueue.length > 0) {
|
|
1207
|
+
isReady = true;
|
|
1208
|
+
}
|
|
1209
|
+
} else if (type === 2) { // EVENTTYPE_FD_WRITE
|
|
1210
|
+
isReady = true;
|
|
1211
|
+
}
|
|
1129
1212
|
|
|
1130
|
-
if (
|
|
1131
|
-
|
|
1213
|
+
if (isReady) {
|
|
1214
|
+
const outEventPtr = out_ptr + nevents * 32;
|
|
1215
|
+
view.setBigUint64(outEventPtr, userdata, true);
|
|
1216
|
+
view.setUint16(outEventPtr + 8, ERRNO_SUCCESS, true);
|
|
1217
|
+
view.setUint8(outEventPtr + 10, type);
|
|
1218
|
+
for (let b = 11; b < 32; b++) view.setUint8(outEventPtr + b, 0);
|
|
1219
|
+
if (type === 1) {
|
|
1220
|
+
view.setBigUint64(outEventPtr + 16, BigInt(inputQueue.length), true);
|
|
1221
|
+
}
|
|
1222
|
+
nevents++;
|
|
1132
1223
|
}
|
|
1133
|
-
nevents++;
|
|
1134
1224
|
}
|
|
1135
1225
|
view.setUint32(nevents_ptr, nevents, true);
|
|
1136
1226
|
return ERRNO_SUCCESS;
|
|
1137
1227
|
}
|
|
1138
1228
|
|
|
1139
1229
|
let immediateCount = 0;
|
|
1230
|
+
let hasFdReadSub = false;
|
|
1140
1231
|
let minTimeoutMs = Infinity;
|
|
1141
1232
|
|
|
1142
1233
|
for (let i = 0; i < nsubscriptions; i++) {
|
|
@@ -1155,6 +1246,7 @@ class WasmCommand extends ScriptCommand {
|
|
|
1155
1246
|
}
|
|
1156
1247
|
if (sleepMs < minTimeoutMs) minTimeoutMs = sleepMs;
|
|
1157
1248
|
} else if (type === 1) { // EVENTTYPE_FD_READ
|
|
1249
|
+
hasFdReadSub = true;
|
|
1158
1250
|
const fd = view.getUint32(subPtr + 16, true);
|
|
1159
1251
|
const entry = fdTable.get(fd);
|
|
1160
1252
|
const isDevTty = Boolean(entry && entry.type === 'dev_tty');
|
|
@@ -1201,22 +1293,42 @@ class WasmCommand extends ScriptCommand {
|
|
|
1201
1293
|
return ERRNO_SUCCESS;
|
|
1202
1294
|
}
|
|
1203
1295
|
|
|
1296
|
+
pollTimedOut = false;
|
|
1297
|
+
pollInterrupted = false;
|
|
1204
1298
|
instance.exports.asyncify_start_unwind(asyncifyDataAddr);
|
|
1205
1299
|
asyncifyPromise = new Promise((resolve, reject) => {
|
|
1206
1300
|
let timer = null;
|
|
1207
1301
|
this._asyncifyReject = reject;
|
|
1208
1302
|
const onKey = () => {
|
|
1209
1303
|
if (timer) clearTimeout(timer);
|
|
1304
|
+
pollTimedOut = false;
|
|
1305
|
+
pollInterrupted = false;
|
|
1210
1306
|
pendingReadResolve = null;
|
|
1307
|
+
pendingResizeInterrupt = null;
|
|
1211
1308
|
this._pendingReadResolve = null;
|
|
1212
1309
|
this._asyncifyReject = null;
|
|
1213
1310
|
resolve();
|
|
1214
1311
|
};
|
|
1215
|
-
|
|
1216
|
-
|
|
1312
|
+
if (hasFdReadSub) {
|
|
1313
|
+
pendingReadResolve = onKey;
|
|
1314
|
+
this._pendingReadResolve = onKey;
|
|
1315
|
+
pendingResizeInterrupt = () => {
|
|
1316
|
+
if (timer) clearTimeout(timer);
|
|
1317
|
+
pollTimedOut = false;
|
|
1318
|
+
pollInterrupted = true;
|
|
1319
|
+
pendingReadResolve = null;
|
|
1320
|
+
pendingResizeInterrupt = null;
|
|
1321
|
+
this._pendingReadResolve = null;
|
|
1322
|
+
this._asyncifyReject = null;
|
|
1323
|
+
resolve();
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1217
1326
|
if (minTimeoutMs !== Infinity) {
|
|
1218
1327
|
timer = setTimeout(() => {
|
|
1328
|
+
pollTimedOut = true;
|
|
1329
|
+
pollInterrupted = false;
|
|
1219
1330
|
pendingReadResolve = null;
|
|
1331
|
+
pendingResizeInterrupt = null;
|
|
1220
1332
|
this._pendingReadResolve = null;
|
|
1221
1333
|
this._asyncifyReject = null;
|
|
1222
1334
|
resolve();
|
|
@@ -1313,24 +1425,64 @@ class WasmCommand extends ScriptCommand {
|
|
|
1313
1425
|
this._enterAltScreen();
|
|
1314
1426
|
}
|
|
1315
1427
|
|
|
1316
|
-
const cols = (this.stdout && this.stdout.columns)
|
|
1317
|
-
|
|
1428
|
+
const cols = (this.stdout && this.stdout.columns)
|
|
1429
|
+
|| (this.stdinStream && this.stdinStream.columns)
|
|
1430
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('COLUMNS'), 10))
|
|
1431
|
+
|| 80;
|
|
1432
|
+
const rows = (this.stdout && this.stdout.rows)
|
|
1433
|
+
|| (this.stdinStream && this.stdinStream.rows)
|
|
1434
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('LINES'), 10))
|
|
1435
|
+
|| 24;
|
|
1318
1436
|
if (typeof instance.exports.set_terminal_size === 'function') {
|
|
1319
1437
|
try { instance.exports.set_terminal_size(cols, rows); } catch {}
|
|
1320
1438
|
}
|
|
1321
1439
|
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1440
|
+
let lastAppliedCols = cols;
|
|
1441
|
+
let lastAppliedRows = rows;
|
|
1442
|
+
const applyResize = (c, r) => {
|
|
1443
|
+
if (!c || !r) return;
|
|
1444
|
+
if (this.stdout && (this.stdout.columns !== c || this.stdout.rows !== r)) {
|
|
1445
|
+
this.stdout.columns = c;
|
|
1446
|
+
this.stdout.rows = r;
|
|
1447
|
+
}
|
|
1448
|
+
if (this.stdinStream && (this.stdinStream.columns !== c || this.stdinStream.rows !== r)) {
|
|
1449
|
+
this.stdinStream.columns = c;
|
|
1450
|
+
this.stdinStream.rows = r;
|
|
1451
|
+
}
|
|
1452
|
+
if (this.context && typeof this.context.setVar === 'function') {
|
|
1453
|
+
try {
|
|
1454
|
+
this.context.setVar('COLUMNS', String(c));
|
|
1455
|
+
this.context.setVar('LINES', String(r));
|
|
1456
|
+
} catch {}
|
|
1457
|
+
}
|
|
1458
|
+
if (c === lastAppliedCols && r === lastAppliedRows) return;
|
|
1459
|
+
lastAppliedCols = c;
|
|
1460
|
+
lastAppliedRows = r;
|
|
1325
1461
|
if (typeof instance?.exports?.set_terminal_size === 'function') {
|
|
1326
1462
|
try { instance.exports.set_terminal_size(c, r); } catch {}
|
|
1327
1463
|
}
|
|
1464
|
+
if (pendingResizeInterrupt) {
|
|
1465
|
+
const intr = pendingResizeInterrupt;
|
|
1466
|
+
pendingResizeInterrupt = null;
|
|
1467
|
+
intr();
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
onStdoutResize = () => {
|
|
1472
|
+
const c = (this.stdout && this.stdout.columns) || (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('COLUMNS'), 10)) || 80;
|
|
1473
|
+
const r = (this.stdout && this.stdout.rows) || (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('LINES'), 10)) || 24;
|
|
1474
|
+
applyResize(c, r);
|
|
1475
|
+
};
|
|
1476
|
+
onStdinResize = () => {
|
|
1477
|
+
const c = (this.stdinStream && this.stdinStream.columns) || (this.stdout && this.stdout.columns) || (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('COLUMNS'), 10)) || 80;
|
|
1478
|
+
const r = (this.stdinStream && this.stdinStream.rows) || (this.stdout && this.stdout.rows) || (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('LINES'), 10)) || 24;
|
|
1479
|
+
applyResize(c, r);
|
|
1328
1480
|
};
|
|
1329
1481
|
if (this.stdout && typeof this.stdout.on === 'function') {
|
|
1330
|
-
this.stdout.on('resize',
|
|
1482
|
+
this.stdout.on('resize', onStdoutResize);
|
|
1331
1483
|
}
|
|
1332
|
-
if (this.stdinStream && typeof this.stdinStream.on === 'function') {
|
|
1333
|
-
this.stdinStream.on('resize',
|
|
1484
|
+
if (this.stdinStream && this.stdinStream !== this.stdout && typeof this.stdinStream.on === 'function') {
|
|
1485
|
+
this.stdinStream.on('resize', onStdinResize);
|
|
1334
1486
|
}
|
|
1335
1487
|
|
|
1336
1488
|
const start = instance.exports._start
|
|
@@ -1401,12 +1553,14 @@ class WasmCommand extends ScriptCommand {
|
|
|
1401
1553
|
if (this.stdinStream && typeof this.stdinStream.off === 'function') this.stdinStream.off('data', onStreamData);
|
|
1402
1554
|
if (this.stdin && typeof this.stdin.off === 'function') this.stdin.off('data', onStreamData);
|
|
1403
1555
|
}
|
|
1404
|
-
if (this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on === 'function') {
|
|
1556
|
+
if (hadDefaultStdinListener && this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on === 'function') {
|
|
1405
1557
|
this.stdinStream.on('data', this._onStdinStreamData);
|
|
1406
1558
|
}
|
|
1407
|
-
if (
|
|
1408
|
-
|
|
1409
|
-
|
|
1559
|
+
if (onStdoutResize && this.stdout && typeof this.stdout.off === 'function') {
|
|
1560
|
+
this.stdout.off('resize', onStdoutResize);
|
|
1561
|
+
}
|
|
1562
|
+
if (onStdinResize && this.stdinStream && typeof this.stdinStream.off === 'function') {
|
|
1563
|
+
this.stdinStream.off('resize', onStdinResize);
|
|
1410
1564
|
}
|
|
1411
1565
|
this._externalKeyHandler = null;
|
|
1412
1566
|
|
|
@@ -1731,10 +1885,10 @@ function formatWasmHelp(binName, pkgMeta = {}, inspected = null) {
|
|
|
1731
1885
|
* which extends `createGenericWasmCommand`.
|
|
1732
1886
|
*/
|
|
1733
1887
|
function createGenericWasmCommand(pkgMeta, config = {}, binNameOverride = null) {
|
|
1734
|
-
const
|
|
1888
|
+
const Command = require('./Command');
|
|
1735
1889
|
const binName = (binNameOverride || pkgMeta.bin || pkgMeta.name).toLowerCase();
|
|
1736
1890
|
|
|
1737
|
-
class GenericWasmCommand extends
|
|
1891
|
+
class GenericWasmCommand extends Command {
|
|
1738
1892
|
static get name() { return binName; }
|
|
1739
1893
|
get name() { return binName; }
|
|
1740
1894
|
get requiresFilesystem() { return true; }
|
|
@@ -1748,9 +1902,25 @@ function createGenericWasmCommand(pkgMeta, config = {}, binNameOverride = null)
|
|
|
1748
1902
|
}
|
|
1749
1903
|
|
|
1750
1904
|
get captureInput() {
|
|
1905
|
+
if (this._subCommand) return Boolean(this._subCommand.captureInput);
|
|
1751
1906
|
return this.interactive;
|
|
1752
1907
|
}
|
|
1753
1908
|
|
|
1909
|
+
get isRaw() {
|
|
1910
|
+
return Boolean(
|
|
1911
|
+
(this.stdinStream && this.stdinStream.isRaw)
|
|
1912
|
+
|| (this._subCommand && (this._subCommand.isRaw || (this._subCommand.stdinStream && this._subCommand.stdinStream.isRaw)))
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
get _inAltScreen() {
|
|
1917
|
+
return Boolean(this.__inAltScreen || (this._subCommand && this._subCommand._inAltScreen));
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
set _inAltScreen(val) {
|
|
1921
|
+
this.__inAltScreen = Boolean(val);
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1754
1924
|
kill(signal = 'SIGINT') {
|
|
1755
1925
|
if (this._subCommand && typeof this._subCommand.kill === 'function') {
|
|
1756
1926
|
this._subCommand.kill(signal);
|
|
@@ -1768,9 +1938,10 @@ function createGenericWasmCommand(pkgMeta, config = {}, binNameOverride = null)
|
|
|
1768
1938
|
const args = [...(this.arguments || [])];
|
|
1769
1939
|
const isHelp = args.includes('--help') || args.includes('-h');
|
|
1770
1940
|
const isVersion = !isHelp && (args.includes('--version') || args.includes('-V') || args.includes('-v'));
|
|
1941
|
+
const fs = this.fs || (this.context && this.context.fs);
|
|
1771
1942
|
this._inspectedWasm = null;
|
|
1772
1943
|
this._persistedWasmBytes = pkgMeta.wasmPath
|
|
1773
|
-
? readBytesFromFs(
|
|
1944
|
+
? readBytesFromFs(fs, pkgMeta.wasmPath)
|
|
1774
1945
|
: null;
|
|
1775
1946
|
if (isHelp && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0) {
|
|
1776
1947
|
this._inspectedWasm = inspectWasmBytes(this._persistedWasmBytes);
|
|
@@ -1948,14 +2119,32 @@ function createGenericWasmCommand(pkgMeta, config = {}, binNameOverride = null)
|
|
|
1948
2119
|
wasmCmd.context = this.context;
|
|
1949
2120
|
wasmCmd.fs = this.fs;
|
|
1950
2121
|
wasmCmd._pkgMeta = pkgMeta;
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
2122
|
+
wasmCmd.stdinStream = this.stdinStream;
|
|
2123
|
+
wasmCmd.stdout = this.stdout;
|
|
2124
|
+
wasmCmd.stderr = this.stderr;
|
|
2125
|
+
wasmCmd.stdin = (this.stdin && !this.stdin.isTTY) ? this.stdin : this.stdinStream;
|
|
2126
|
+
if (this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off === 'function') {
|
|
2127
|
+
this.stdinStream.off('data', this._onStdinStreamData);
|
|
2128
|
+
}
|
|
2129
|
+
const onSubInteractive = () => {
|
|
2130
|
+
this.emit('interactive');
|
|
2131
|
+
if (this.context && typeof this.context.emit === 'function') {
|
|
2132
|
+
this.context.emit('interactive');
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
wasmCmd.on('interactive', onSubInteractive);
|
|
1954
2136
|
this._subCommand = wasmCmd;
|
|
1955
2137
|
try {
|
|
1956
2138
|
await wasmCmd._runWasm(bytes);
|
|
1957
2139
|
} finally {
|
|
2140
|
+
wasmCmd.removeListener('interactive', onSubInteractive);
|
|
2141
|
+
if (wasmCmd._inAltScreen) {
|
|
2142
|
+
wasmCmd._exitAltScreen();
|
|
2143
|
+
}
|
|
1958
2144
|
this._subCommand = null;
|
|
2145
|
+
if (this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on === 'function') {
|
|
2146
|
+
this.stdinStream.on('data', this._onStdinStreamData);
|
|
2147
|
+
}
|
|
1959
2148
|
}
|
|
1960
2149
|
for (const line of wasmCmd.result.getStdOutput()) {
|
|
1961
2150
|
if (line.type === 'out') this.stdOut = line.string;
|
|
@@ -2007,8 +2196,7 @@ function createGenericWasmCommand(pkgMeta, config = {}, binNameOverride = null)
|
|
|
2007
2196
|
}
|
|
2008
2197
|
if (targetPath.endsWith('.wasm') || targetPath.endsWith('.wat')) {
|
|
2009
2198
|
try {
|
|
2010
|
-
|
|
2011
|
-
else this.fs.setMode(targetPath, 0o755);
|
|
2199
|
+
this.fs.setMode(targetPath, 0o755);
|
|
2012
2200
|
} catch { /* ignore */ }
|
|
2013
2201
|
}
|
|
2014
2202
|
},
|
|
@@ -2304,8 +2492,7 @@ function createGenericWasmCommand(pkgMeta, config = {}, binNameOverride = null)
|
|
|
2304
2492
|
writeBytesToFs(this.fs, arg, data, mime);
|
|
2305
2493
|
if (arg.endsWith('.wasm') || arg.endsWith('.wat')) {
|
|
2306
2494
|
try {
|
|
2307
|
-
|
|
2308
|
-
else this.fs.setMode(arg, 0o755);
|
|
2495
|
+
this.fs.setMode(arg, 0o755);
|
|
2309
2496
|
} catch { /* ignore */ }
|
|
2310
2497
|
}
|
|
2311
2498
|
}
|