brsh 3.9.0 → 3.10.1
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/Readme.md +22 -4
- package/bin/Readme.md +33 -3
- package/bin/exportFileSystem.js +127 -110
- package/bin/wbt.js +118 -0
- package/dist/shell.es.js +4074 -3717
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +26 -25
- 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 +3082 -2710
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +16 -12
- package/dist/wbt.min.js.map +1 -1
- package/index.js +102 -80
- package/lib/BaseFileSystem.js +57 -2
- package/lib/BinaryContainer.js +1 -1
- package/lib/Command.js +1 -1
- package/lib/Context.js +4 -3
- package/lib/FileSystem.js +4 -2
- package/lib/InteractiveCommand.js +9 -8
- package/lib/JsCommand.js +113 -0
- package/lib/NodeFileSystem.js +164 -30
- package/lib/Readme.md +1 -0
- package/lib/ScriptCommand.js +148 -8
- package/lib/Terminal.js +60 -6
- package/lib/TtyStream.js +36 -2
- package/lib/WasmCommand.js +313 -66
- package/lib/buildFilesystemStructure.js +38 -24
- package/lib/isUtf8Text.js +47 -0
- package/lib/local/which.js +8 -3
- package/lib/wbt/index.js +473 -175
- package/lib/wbt/registry.js +21 -1
- package/package.json +3 -2
- package/test/devices-signals.test.js +112 -0
- package/test/doom.test.js +7 -4
- package/test/exportFileSystem.test.js +37 -15
- package/test/js-command.test.js +125 -0
- package/test/node-filesystem.test.js +7 -0
- package/test/scripts.test.js +30 -0
- package/test/terminal.test.js +148 -0
- package/test/wasm-cli.test.js +76 -0
- package/test/wbt.test.js +418 -10
- package/test/wbtCli.test.js +160 -0
package/lib/Terminal.js
CHANGED
|
@@ -170,6 +170,7 @@ class Terminal {
|
|
|
170
170
|
cursor: this._cursor,
|
|
171
171
|
urlWhitelist: DEFAULT_URL_WHITELIST
|
|
172
172
|
});
|
|
173
|
+
this._measureAndSetSize();
|
|
173
174
|
|
|
174
175
|
this._listenForEvents();
|
|
175
176
|
|
|
@@ -571,7 +572,7 @@ class Terminal {
|
|
|
571
572
|
if (this.screen.isAltScreen) return true;
|
|
572
573
|
if (this.cli && this.cli.runningCommand) {
|
|
573
574
|
const cmd = this.cli.runningCommand;
|
|
574
|
-
if (cmd.interactive || cmd._inAltScreen || (cmd.stdinStream && cmd.stdinStream.isRaw)) {
|
|
575
|
+
if (cmd.interactive || cmd._inAltScreen || cmd.isRaw || (cmd.stdinStream && cmd.stdinStream.isRaw)) {
|
|
575
576
|
return true;
|
|
576
577
|
}
|
|
577
578
|
}
|
|
@@ -594,15 +595,28 @@ class Terminal {
|
|
|
594
595
|
return false;
|
|
595
596
|
}
|
|
596
597
|
|
|
597
|
-
_encodeKey(
|
|
598
|
+
_encodeKey(rawKey, modifiers = {}) {
|
|
598
599
|
const { alt = false, ctrl = false, shift = false, meta = false } = modifiers;
|
|
599
|
-
if (!
|
|
600
|
+
if (!rawKey || ['Control', 'Alt', 'Shift', 'Meta', 'CapsLock', 'NumLock', 'ScrollLock', 'Dead', 'Unidentified'].includes(rawKey)) {
|
|
600
601
|
return null;
|
|
601
602
|
}
|
|
602
603
|
|
|
603
604
|
// Allow native browser copy/paste/reload shortcuts with Meta (Cmd on macOS)
|
|
604
605
|
if (meta) return null;
|
|
605
606
|
|
|
607
|
+
const keyAliases = {
|
|
608
|
+
Up: 'ArrowUp',
|
|
609
|
+
Down: 'ArrowDown',
|
|
610
|
+
Right: 'ArrowRight',
|
|
611
|
+
Left: 'ArrowLeft',
|
|
612
|
+
Esc: 'Escape',
|
|
613
|
+
Return: 'Enter',
|
|
614
|
+
Del: 'Delete',
|
|
615
|
+
Space: ' ',
|
|
616
|
+
Spacebar: ' '
|
|
617
|
+
};
|
|
618
|
+
const key = keyAliases[rawKey] || rawKey;
|
|
619
|
+
|
|
606
620
|
const appCursor = this.parser.applicationCursorKeys;
|
|
607
621
|
|
|
608
622
|
if (key === 'ArrowUp') {
|
|
@@ -749,6 +763,7 @@ class Terminal {
|
|
|
749
763
|
this._cmdList.style.listStyle = 'none';
|
|
750
764
|
this._cmdList.style.padding = '0';
|
|
751
765
|
this._cmdList.style.margin = '0';
|
|
766
|
+
this._cmdList.style.lineHeight = '1.15em';
|
|
752
767
|
if (this._lineWrap) {
|
|
753
768
|
this._cmdList.classList.add('terminal--wrap');
|
|
754
769
|
}
|
|
@@ -757,6 +772,13 @@ class Terminal {
|
|
|
757
772
|
this._charMeasure = document.createElement('span');
|
|
758
773
|
this._charMeasure.className = 'terminal__char-measure';
|
|
759
774
|
this._charMeasure.style.fontFamily = `'${font}', monospace`;
|
|
775
|
+
this._charMeasure.style.position = 'absolute';
|
|
776
|
+
this._charMeasure.style.top = '0';
|
|
777
|
+
this._charMeasure.style.left = '0';
|
|
778
|
+
this._charMeasure.style.visibility = 'hidden';
|
|
779
|
+
this._charMeasure.style.pointerEvents = 'none';
|
|
780
|
+
this._charMeasure.style.whiteSpace = 'pre';
|
|
781
|
+
this._charMeasure.style.lineHeight = '1.15em';
|
|
760
782
|
this._charMeasure.textContent = 'X';
|
|
761
783
|
this._charMeasure.setAttribute('aria-hidden', 'true');
|
|
762
784
|
parent.appendChild(this._charMeasure);
|
|
@@ -766,14 +788,19 @@ class Terminal {
|
|
|
766
788
|
document.fonts.ready.then(() => this._measureAndSetSize());
|
|
767
789
|
}
|
|
768
790
|
if (typeof ResizeObserver !== 'undefined') {
|
|
769
|
-
new ResizeObserver(() => this._measureAndSetSize())
|
|
791
|
+
this._resizeObserver = new ResizeObserver(() => this._measureAndSetSize());
|
|
792
|
+
this._resizeObserver.observe(parent);
|
|
770
793
|
}
|
|
771
794
|
}
|
|
772
795
|
|
|
773
796
|
_listenForEvents() {
|
|
774
797
|
if (typeof window === 'undefined') return;
|
|
775
798
|
|
|
799
|
+
this._onWindowResize = () => this._measureAndSetSize();
|
|
800
|
+
window.addEventListener('resize', this._onWindowResize);
|
|
801
|
+
|
|
776
802
|
this._onKeyDown = (e) => {
|
|
803
|
+
if (!e || e.defaultPrevented || e.isComposing || e.keyCode === 229) return;
|
|
777
804
|
if (e.metaKey) return;
|
|
778
805
|
const seq = this._encodeKey(e.key, {
|
|
779
806
|
alt: Boolean(e.altKey),
|
|
@@ -1033,8 +1060,30 @@ class Terminal {
|
|
|
1033
1060
|
if (!charRect || !containerRect || !charRect.width || !charRect.height || !containerRect.width) return;
|
|
1034
1061
|
// Ignore degenerate/mock measurements where single-char span equals container size
|
|
1035
1062
|
if (charRect.width >= containerRect.width && charRect.height >= containerRect.height) return;
|
|
1036
|
-
|
|
1037
|
-
|
|
1063
|
+
|
|
1064
|
+
let availWidth = (typeof this._el.clientWidth === 'number' && this._el.clientWidth > 0)
|
|
1065
|
+
? this._el.clientWidth
|
|
1066
|
+
: containerRect.width;
|
|
1067
|
+
let availHeight = (typeof this._el.clientHeight === 'number' && this._el.clientHeight > 0)
|
|
1068
|
+
? this._el.clientHeight
|
|
1069
|
+
: (containerRect.height || (charRect.height * 24));
|
|
1070
|
+
|
|
1071
|
+
if (typeof window !== 'undefined' && typeof window.getComputedStyle === 'function') {
|
|
1072
|
+
try {
|
|
1073
|
+
const cs = window.getComputedStyle(this._el);
|
|
1074
|
+
if (cs) {
|
|
1075
|
+
const padX = (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
|
|
1076
|
+
const padY = (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0);
|
|
1077
|
+
if (availWidth > padX) availWidth -= padX;
|
|
1078
|
+
if (availHeight > padY) availHeight -= padY;
|
|
1079
|
+
}
|
|
1080
|
+
} catch (_) {
|
|
1081
|
+
// ignore getComputedStyle errors
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
const cols = Math.max(1, Math.floor(availWidth / charRect.width));
|
|
1086
|
+
const rows = Math.max(1, Math.floor(availHeight / charRect.height));
|
|
1038
1087
|
if (cols !== this._lastCols || rows !== this._lastRows) {
|
|
1039
1088
|
this.resize(cols, rows);
|
|
1040
1089
|
}
|
|
@@ -1045,7 +1094,12 @@ class Terminal {
|
|
|
1045
1094
|
clearInterval(this._typeTimer);
|
|
1046
1095
|
this._typeTimer = null;
|
|
1047
1096
|
}
|
|
1097
|
+
if (this._resizeObserver && typeof this._resizeObserver.disconnect === 'function') {
|
|
1098
|
+
this._resizeObserver.disconnect();
|
|
1099
|
+
this._resizeObserver = null;
|
|
1100
|
+
}
|
|
1048
1101
|
if (typeof window !== 'undefined' && window.removeEventListener) {
|
|
1102
|
+
if (this._onWindowResize) window.removeEventListener('resize', this._onWindowResize);
|
|
1049
1103
|
if (this._onKeyDown) window.removeEventListener('keydown', this._onKeyDown);
|
|
1050
1104
|
if (this._onPaste) window.removeEventListener('paste', this._onPaste);
|
|
1051
1105
|
}
|
package/lib/TtyStream.js
CHANGED
|
@@ -38,16 +38,35 @@ function parseVtKeys(seq) {
|
|
|
38
38
|
D: 'ArrowLeft',
|
|
39
39
|
H: 'Home',
|
|
40
40
|
F: 'End',
|
|
41
|
+
Z: 'BackTab',
|
|
42
|
+
P: 'F1',
|
|
43
|
+
Q: 'F2',
|
|
44
|
+
R: 'F3',
|
|
45
|
+
S: 'F4',
|
|
41
46
|
'1~': 'Home',
|
|
47
|
+
'2~': 'Insert',
|
|
42
48
|
'3~': 'Delete',
|
|
43
49
|
'4~': 'End',
|
|
44
50
|
'5~': 'PageUp',
|
|
45
51
|
'6~': 'PageDown',
|
|
46
52
|
'7~': 'Home',
|
|
47
|
-
'8~': 'End'
|
|
53
|
+
'8~': 'End',
|
|
54
|
+
'15~': 'F5',
|
|
55
|
+
'17~': 'F6',
|
|
56
|
+
'18~': 'F7',
|
|
57
|
+
'19~': 'F8',
|
|
58
|
+
'20~': 'F9',
|
|
59
|
+
'21~': 'F10',
|
|
60
|
+
'23~': 'F11',
|
|
61
|
+
'24~': 'F12'
|
|
48
62
|
};
|
|
49
63
|
if (map[body]) {
|
|
50
64
|
keys.push(map[body]);
|
|
65
|
+
} else {
|
|
66
|
+
const modCursor = body.match(/^1;\d+([ABCDHF])$/);
|
|
67
|
+
if (modCursor && map[modCursor[1]]) {
|
|
68
|
+
keys.push(map[modCursor[1]]);
|
|
69
|
+
}
|
|
51
70
|
}
|
|
52
71
|
i = j + 1;
|
|
53
72
|
continue;
|
|
@@ -185,7 +204,22 @@ class TtyStream extends EventEmitter {
|
|
|
185
204
|
}
|
|
186
205
|
}
|
|
187
206
|
|
|
207
|
+
function hasCustomStdinListener(cmd) {
|
|
208
|
+
if (!cmd || cmd._managesOwnStdinCapture || !cmd.stdinStream || typeof cmd.stdinStream.listenerCount !== 'function') {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
const count = cmd.stdinStream.listenerCount('data');
|
|
212
|
+
if (count === 0) return false;
|
|
213
|
+
if (cmd._onStdinStreamData && typeof cmd.stdinStream.listeners === 'function') {
|
|
214
|
+
const hasDefault = cmd.stdinStream.listeners('data').includes(cmd._onStdinStreamData);
|
|
215
|
+
return count > (hasDefault ? 1 : 0);
|
|
216
|
+
}
|
|
217
|
+
return count > 0;
|
|
218
|
+
}
|
|
219
|
+
|
|
188
220
|
module.exports = {
|
|
189
221
|
TtyStream,
|
|
190
|
-
parseVtKeys
|
|
222
|
+
parseVtKeys,
|
|
223
|
+
hasCustomStdinListener
|
|
191
224
|
};
|
|
225
|
+
|