brsh 3.10.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 +7 -0
- package/dist/shell.es.js +704 -583
- 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 +842 -662
- 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 +36 -9
- 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 +57 -20
- 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/terminal.test.js +148 -0
- package/test/wasm-cli.test.js +76 -0
- package/test/wbt.test.js +111 -1
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const WasmCommand = require('./lib/WasmCommand');
|
|
|
7
7
|
const JsCommand = require('./lib/JsCommand');
|
|
8
8
|
const Command = require('./lib/Command');
|
|
9
9
|
const InteractiveCommand = require('./lib/InteractiveCommand');
|
|
10
|
-
const { TtyStream } = require('./lib/TtyStream');
|
|
10
|
+
const { TtyStream, hasCustomStdinListener } = require('./lib/TtyStream');
|
|
11
11
|
|
|
12
12
|
const HISTORY_FILE = '/.brsh_history';
|
|
13
13
|
|
|
@@ -45,7 +45,9 @@ class Shell extends EventEmitter {
|
|
|
45
45
|
permissions = {},
|
|
46
46
|
cwd = '/',
|
|
47
47
|
onFsChange,
|
|
48
|
-
useRealFilesystem = false
|
|
48
|
+
useRealFilesystem = false,
|
|
49
|
+
cols,
|
|
50
|
+
rows
|
|
49
51
|
} = options;
|
|
50
52
|
|
|
51
53
|
this.context = new Context(Object.assign({}, options, {
|
|
@@ -78,15 +80,23 @@ class Shell extends EventEmitter {
|
|
|
78
80
|
this._loadingFs = null;
|
|
79
81
|
this._queuedWhileLoading = false;
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
const initCols = (typeof cols === 'number' && cols > 0) ? Math.floor(cols) : 80;
|
|
84
|
+
const initRows = (typeof rows === 'number' && rows > 0) ? Math.floor(rows) : 24;
|
|
85
|
+
if ((typeof cols === 'number' && cols > 0) || (typeof rows === 'number' && rows > 0)) {
|
|
86
|
+
this._terminalSize = { cols: initCols, rows: initRows };
|
|
87
|
+
this.context.setVar('COLUMNS', String(initCols));
|
|
88
|
+
this.context.setVar('LINES', String(initRows));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.stdinStream = new TtyStream({ columns: initCols, rows: initRows });
|
|
82
92
|
this.stdout = new TtyStream({
|
|
83
|
-
columns:
|
|
84
|
-
rows:
|
|
93
|
+
columns: initCols,
|
|
94
|
+
rows: initRows,
|
|
85
95
|
onWrite: (chunk) => this.emit('data', chunk)
|
|
86
96
|
});
|
|
87
97
|
this.stderr = new TtyStream({
|
|
88
|
-
columns:
|
|
89
|
-
rows:
|
|
98
|
+
columns: initCols,
|
|
99
|
+
rows: initRows,
|
|
90
100
|
onWrite: (chunk) => this.emit('data', chunk)
|
|
91
101
|
});
|
|
92
102
|
|
|
@@ -702,6 +712,22 @@ class Shell extends EventEmitter {
|
|
|
702
712
|
};
|
|
703
713
|
|
|
704
714
|
this.runningCommand = instance;
|
|
715
|
+
const liveCols = (this.stdout && this.stdout.columns) || (this.stdinStream && this.stdinStream.columns);
|
|
716
|
+
const liveRows = (this.stdout && this.stdout.rows) || (this.stdinStream && this.stdinStream.rows);
|
|
717
|
+
if (liveCols && liveRows) {
|
|
718
|
+
if (instance.stdinStream) {
|
|
719
|
+
instance.stdinStream.columns = liveCols;
|
|
720
|
+
instance.stdinStream.rows = liveRows;
|
|
721
|
+
}
|
|
722
|
+
if (instance.stdout) {
|
|
723
|
+
instance.stdout.columns = liveCols;
|
|
724
|
+
instance.stdout.rows = liveRows;
|
|
725
|
+
}
|
|
726
|
+
if (instance.stderr) {
|
|
727
|
+
instance.stderr.columns = liveCols;
|
|
728
|
+
instance.stderr.rows = liveRows;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
705
731
|
if(this.runningCommand.on) {
|
|
706
732
|
this.runningCommand.on('flush', lines => {
|
|
707
733
|
lines.forEach(routeLine);
|
|
@@ -1018,7 +1044,8 @@ class Shell extends EventEmitter {
|
|
|
1018
1044
|
|| (raw instanceof Uint8Array && raw.length === 1 && raw[0] === 3)
|
|
1019
1045
|
|| ((typeof Buffer !== 'undefined' && Buffer.isBuffer(raw)) && raw.length === 1 && raw[0] === 3);
|
|
1020
1046
|
|
|
1021
|
-
|
|
1047
|
+
const cmdIsRaw = Boolean(cmd.isRaw || (cmd.stdinStream && cmd.stdinStream.isRaw));
|
|
1048
|
+
if (isCtrlC && !cmdIsRaw) {
|
|
1022
1049
|
if (typeof cmd.kill === 'function') {
|
|
1023
1050
|
cmd.kill('SIGINT');
|
|
1024
1051
|
}
|
|
@@ -1028,7 +1055,7 @@ class Shell extends EventEmitter {
|
|
|
1028
1055
|
return;
|
|
1029
1056
|
}
|
|
1030
1057
|
|
|
1031
|
-
const hasStreamListeners = cmd
|
|
1058
|
+
const hasStreamListeners = hasCustomStdinListener(cmd);
|
|
1032
1059
|
if (cmd.captureInput || cmd.interactive || cmd._inAltScreen || hasStreamListeners) {
|
|
1033
1060
|
cmd.stdinStream.pushData(raw);
|
|
1034
1061
|
return;
|
package/lib/BaseFileSystem.js
CHANGED
|
@@ -101,8 +101,10 @@ class BaseFileSystem {
|
|
|
101
101
|
// Only the public API is accessible; raw/internal methods are blocked.
|
|
102
102
|
sandbox() {
|
|
103
103
|
const target = this;
|
|
104
|
+
const targetSym = Symbol.for('brsh.fs.target');
|
|
104
105
|
return new Proxy(Object.create(null), {
|
|
105
106
|
get(_, prop) {
|
|
107
|
+
if (prop === targetSym) return target;
|
|
106
108
|
if (!SANDBOX_ALLOWED.has(prop)) return undefined;
|
|
107
109
|
const val = target[prop];
|
|
108
110
|
return typeof val === 'function' ? val.bind(target) : val;
|
package/lib/BinaryContainer.js
CHANGED
|
@@ -81,7 +81,7 @@ function serializeBinaryFilesystem(filesystem = {}, permissions = {}, options =
|
|
|
81
81
|
// If an external commandsBundle is provided, reference by virtualPath;
|
|
82
82
|
// otherwise store the function's source code so client-side persistence works standalone!
|
|
83
83
|
if (!options.commandsBundle) {
|
|
84
|
-
inlineCommandSources[virtualPath] = node.toString();
|
|
84
|
+
inlineCommandSources[virtualPath] = node.__source || node.toString();
|
|
85
85
|
}
|
|
86
86
|
return { $c: virtualPath };
|
|
87
87
|
}
|
package/lib/Command.js
CHANGED
|
@@ -33,7 +33,7 @@ class Command extends EventEmitter {
|
|
|
33
33
|
if (!this.captureInput) return;
|
|
34
34
|
const keys = parseVtKeys(chunk);
|
|
35
35
|
for (const k of keys) {
|
|
36
|
-
if (k === '^C') {
|
|
36
|
+
if (k === '^C' && !(this.stdinStream && this.stdinStream.isRaw)) {
|
|
37
37
|
this.kill('SIGINT');
|
|
38
38
|
return;
|
|
39
39
|
}
|
package/lib/Context.js
CHANGED
|
@@ -78,8 +78,9 @@ class Context {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
source(context) {
|
|
81
|
-
|
|
82
|
-
this.
|
|
81
|
+
if (!context) return;
|
|
82
|
+
this.vars = Object.assign({}, this.vars, context.vars || {});
|
|
83
|
+
this.aliases = Object.assign({}, this.aliases, context.aliases || {});
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
clear() {
|
|
@@ -41,13 +41,14 @@ class InteractiveCommand extends Command {
|
|
|
41
41
|
* @returns {{ cols: number, rows: number }}
|
|
42
42
|
*/
|
|
43
43
|
get terminalSize() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const cols = (this.stdout && this.stdout.columns)
|
|
45
|
+
|| (this.stdinStream && this.stdinStream.columns)
|
|
46
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('COLUMNS'), 10))
|
|
47
|
+
|| 80;
|
|
48
|
+
const rows = (this.stdout && this.stdout.rows)
|
|
49
|
+
|| (this.stdinStream && this.stdinStream.rows)
|
|
50
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('LINES'), 10))
|
|
51
|
+
|| 24;
|
|
51
52
|
return { cols, rows };
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -62,7 +63,7 @@ class InteractiveCommand extends Command {
|
|
|
62
63
|
if (!this._inAltScreen) return;
|
|
63
64
|
this._inAltScreen = false;
|
|
64
65
|
if (this.stdinStream) this.stdinStream.setRawMode(false);
|
|
65
|
-
if (this.stdout) this.stdout.write('\x1b[?1049l\x1b[?25h');
|
|
66
|
+
if (this.stdout) this.stdout.write('\x1b[0m\x1b[?1l\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?1049l\x1b[?25h');
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
kill(signal = 'SIGINT') {
|
package/lib/ScriptCommand.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const LocalCommand = require('./local/LocalCommand');
|
|
4
|
+
const { parseVtKeys, hasCustomStdinListener } = require('./TtyStream');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Returns true if the first line of a file is a shebang for a known/supported
|
|
@@ -21,9 +22,14 @@ class ScriptCommand extends LocalCommand {
|
|
|
21
22
|
// (e.g. an active `read` or interactive TUI/WASM app). This prevents swallowing
|
|
22
23
|
// keystrokes during normal non-interactive command execution.
|
|
23
24
|
get captureInput() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (!this.sandbox || !this.sandbox.runningCommand) return false;
|
|
26
|
+
const child = this.sandbox.runningCommand;
|
|
27
|
+
return Boolean(
|
|
28
|
+
child.captureInput
|
|
29
|
+
|| child.interactive
|
|
30
|
+
|| child._inAltScreen
|
|
31
|
+
|| hasCustomStdinListener(child)
|
|
32
|
+
);
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
get interactive() {
|
|
@@ -32,6 +38,16 @@ class ScriptCommand extends LocalCommand {
|
|
|
32
38
|
&& this.sandbox.runningCommand.interactive);
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
get isRaw() {
|
|
42
|
+
return Boolean(
|
|
43
|
+
(this.stdinStream && this.stdinStream.isRaw)
|
|
44
|
+
|| (this.sandbox
|
|
45
|
+
&& this.sandbox.runningCommand
|
|
46
|
+
&& (this.sandbox.runningCommand.isRaw
|
|
47
|
+
|| (this.sandbox.runningCommand.stdinStream && this.sandbox.runningCommand.stdinStream.isRaw)))
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
get _inAltScreen() {
|
|
36
52
|
return Boolean(
|
|
37
53
|
this.__inAltScreen ||
|
|
@@ -62,7 +78,9 @@ class ScriptCommand extends LocalCommand {
|
|
|
62
78
|
}
|
|
63
79
|
|
|
64
80
|
run() {
|
|
65
|
-
|
|
81
|
+
this._managesOwnStdinCapture = true;
|
|
82
|
+
const rawRef = (this.context && this.context.fs) || this.fs;
|
|
83
|
+
const fs = (rawRef && rawRef[Symbol.for('brsh.fs.target')]) || rawRef;
|
|
66
84
|
const fsOpts = fs && fs.isRealFilesystem
|
|
67
85
|
? { useRealFilesystem: true }
|
|
68
86
|
: { filesystem: (fs && fs.getRaw()) || {}, permissions: (fs && fs.getRawPermissions()) || {} };
|
|
@@ -73,8 +91,14 @@ class ScriptCommand extends LocalCommand {
|
|
|
73
91
|
});
|
|
74
92
|
this.sandbox.context.source(this.context);
|
|
75
93
|
|
|
76
|
-
const cols = (this.
|
|
77
|
-
|
|
94
|
+
const cols = (this.stdout && this.stdout.columns)
|
|
95
|
+
|| (this.stdinStream && this.stdinStream.columns)
|
|
96
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('COLUMNS'), 10))
|
|
97
|
+
|| 80;
|
|
98
|
+
const rows = (this.stdout && this.stdout.rows)
|
|
99
|
+
|| (this.stdinStream && this.stdinStream.rows)
|
|
100
|
+
|| (this.context && typeof this.context.getVar === 'function' && parseInt(this.context.getVar('LINES'), 10))
|
|
101
|
+
|| 24;
|
|
78
102
|
if (typeof this.sandbox.setTerminalSize === 'function') {
|
|
79
103
|
this.sandbox.setTerminalSize(cols, rows);
|
|
80
104
|
}
|
|
@@ -96,7 +120,7 @@ class ScriptCommand extends LocalCommand {
|
|
|
96
120
|
const onParentStdin = (chunk) => {
|
|
97
121
|
if (!this.sandbox || !this.sandbox.runningCommand) return;
|
|
98
122
|
const child = this.sandbox.runningCommand;
|
|
99
|
-
const hasStreamListeners = child
|
|
123
|
+
const hasStreamListeners = hasCustomStdinListener(child);
|
|
100
124
|
if (child.interactive || child._inAltScreen || hasStreamListeners) {
|
|
101
125
|
if (child.stdinStream) {
|
|
102
126
|
child.stdinStream.pushData(chunk);
|
|
@@ -104,13 +128,13 @@ class ScriptCommand extends LocalCommand {
|
|
|
104
128
|
return;
|
|
105
129
|
}
|
|
106
130
|
if (child.captureInput && typeof child.onInput === 'function') {
|
|
107
|
-
const
|
|
131
|
+
const childIsRaw = Boolean(child.isRaw || (child.stdinStream && child.stdinStream.isRaw));
|
|
108
132
|
for (const k of parseVtKeys(chunk)) {
|
|
109
|
-
if (k === '^C') {
|
|
133
|
+
if (k === '^C' && !childIsRaw) {
|
|
110
134
|
this.kill('SIGINT');
|
|
111
135
|
return;
|
|
112
136
|
}
|
|
113
|
-
if (!
|
|
137
|
+
if (!childIsRaw) {
|
|
114
138
|
if (k === 'Enter') this.stdout.write('\r\n');
|
|
115
139
|
else if (k === 'Backspace') this.stdout.write('\b \b');
|
|
116
140
|
else if (k.length === 1) this.stdout.write(k);
|
|
@@ -120,15 +144,34 @@ class ScriptCommand extends LocalCommand {
|
|
|
120
144
|
}
|
|
121
145
|
};
|
|
122
146
|
|
|
123
|
-
const
|
|
147
|
+
const onParentStdinResize = () => {
|
|
124
148
|
if (this.sandbox && typeof this.sandbox.setTerminalSize === 'function' && this.stdinStream) {
|
|
125
149
|
this.sandbox.setTerminalSize(this.stdinStream.columns, this.stdinStream.rows);
|
|
126
150
|
}
|
|
127
151
|
};
|
|
128
152
|
|
|
153
|
+
const onParentStdoutResize = () => {
|
|
154
|
+
if (this.sandbox && typeof this.sandbox.setTerminalSize === 'function' && this.stdout) {
|
|
155
|
+
this.sandbox.setTerminalSize(this.stdout.columns, this.stdout.rows);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const cleanupListeners = () => {
|
|
160
|
+
if (this.stdinStream && typeof this.stdinStream.off === 'function') {
|
|
161
|
+
this.stdinStream.off('data', onParentStdin);
|
|
162
|
+
this.stdinStream.off('resize', onParentStdinResize);
|
|
163
|
+
}
|
|
164
|
+
if (this.stdout && typeof this.stdout.off === 'function') {
|
|
165
|
+
this.stdout.off('resize', onParentStdoutResize);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
129
169
|
if (this.stdinStream && typeof this.stdinStream.on === 'function') {
|
|
130
170
|
this.stdinStream.on('data', onParentStdin);
|
|
131
|
-
this.stdinStream.on('resize',
|
|
171
|
+
this.stdinStream.on('resize', onParentStdinResize);
|
|
172
|
+
}
|
|
173
|
+
if (this.stdout && this.stdout !== this.stdinStream && typeof this.stdout.on === 'function') {
|
|
174
|
+
this.stdout.on('resize', onParentStdoutResize);
|
|
132
175
|
}
|
|
133
176
|
|
|
134
177
|
this.sandbox.on('stdOut', data => { this.stdOut = data; this.flush(); });
|
|
@@ -156,10 +199,7 @@ class ScriptCommand extends LocalCommand {
|
|
|
156
199
|
const interpreter = lines[0].startsWith('#!')
|
|
157
200
|
? lines[0].slice(2).split(/\s/)[0]
|
|
158
201
|
: lines[0];
|
|
159
|
-
|
|
160
|
-
this.stdinStream.off('data', onParentStdin);
|
|
161
|
-
this.stdinStream.off('resize', onParentResize);
|
|
162
|
-
}
|
|
202
|
+
cleanupListeners();
|
|
163
203
|
return Promise.reject(`${interpreter}: bad interpreter: No such file or directory`);
|
|
164
204
|
}
|
|
165
205
|
|
|
@@ -178,10 +218,7 @@ class ScriptCommand extends LocalCommand {
|
|
|
178
218
|
}
|
|
179
219
|
})
|
|
180
220
|
.finally(() => {
|
|
181
|
-
|
|
182
|
-
this.stdinStream.off('data', onParentStdin);
|
|
183
|
-
this.stdinStream.off('resize', onParentResize);
|
|
184
|
-
}
|
|
221
|
+
cleanupListeners();
|
|
185
222
|
})
|
|
186
223
|
.then(() => {
|
|
187
224
|
this.exitCode = this.sandbox.lastCode;
|
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
|
+
|