brsh 3.1.2 → 3.1.4
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 +9 -4
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +4 -3
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +2 -2
- package/dist/terminal.cjs.js.map +1 -1
- package/dist/terminal.es.js +5 -5
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +2 -2
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +1 -1
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +1 -1
- package/dist/wbt.min.js.map +1 -1
- package/index.js +10 -3
- package/lib/ScriptCommand.js +8 -0
- package/lib/Terminal.js +32 -5
- package/package.json +1 -1
- package/test/scripts.test.js +29 -0
- package/test/terminal.test.js +51 -0
package/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const BaseFileSystem = require('./lib/BaseFileSystem');
|
|
|
18
18
|
const BinaryContainer = require('./lib/BinaryContainer');
|
|
19
19
|
const { isAsyncFilesystemSource, resolveFilesystemSource } = BinaryContainer;
|
|
20
20
|
|
|
21
|
-
const variableRegex = /\$(?:\{([\w\d
|
|
21
|
+
const variableRegex = /\$(?:\{([\w\d?#@*-]+)\}|([\w\d]+|[?#@*-]))/g;
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
const EventEmitter = events.EventEmitter || events.default || events;
|
|
@@ -1016,8 +1016,7 @@ class Shell extends EventEmitter {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
|
|
1018
1018
|
_splitInput(input) {
|
|
1019
|
-
|
|
1020
|
-
return this._parseOperators(commentStripped);
|
|
1019
|
+
return this._parseOperators(input);
|
|
1021
1020
|
}
|
|
1022
1021
|
|
|
1023
1022
|
_parseOperators(input) {
|
|
@@ -1031,6 +1030,14 @@ class Shell extends EventEmitter {
|
|
|
1031
1030
|
if (ch === "'" && !dq) { sq = !sq; current += ch; i++; continue; }
|
|
1032
1031
|
if (ch === '"' && !sq) { dq = !dq; current += ch; i++; continue; }
|
|
1033
1032
|
if (!sq && !dq) {
|
|
1033
|
+
if (ch === '#' && (current.trim() === '' || /\s/.test(input[i - 1]))) {
|
|
1034
|
+
const nextNewline = input.indexOf('\n', i);
|
|
1035
|
+
if (nextNewline === -1) {
|
|
1036
|
+
break;
|
|
1037
|
+
}
|
|
1038
|
+
i = nextNewline;
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1034
1041
|
if (ch === '&' && input[i + 1] === '&') {
|
|
1035
1042
|
segments.push({ command: current.trim(), op: '&&' });
|
|
1036
1043
|
current = ''; i += 2; continue;
|
package/lib/ScriptCommand.js
CHANGED
|
@@ -44,6 +44,14 @@ class ScriptCommand extends LocalCommand {
|
|
|
44
44
|
});
|
|
45
45
|
this.sandbox.context.source(this.context);
|
|
46
46
|
|
|
47
|
+
if (Array.isArray(this.arguments)) {
|
|
48
|
+
this.arguments.forEach((arg, i) =>
|
|
49
|
+
this.sandbox.context.setVar(String(i + 1), arg));
|
|
50
|
+
this.sandbox.context.setVar('#', String(this.arguments.length));
|
|
51
|
+
this.sandbox.context.setVar('@', this.arguments.join(' '));
|
|
52
|
+
this.sandbox.context.setVar('*', this.arguments.join(' '));
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
this.sandbox.on('stdOut', data => { this.stdOut = data; this.flush(); });
|
|
48
56
|
this.sandbox.on('stdErr', data => { this.stdErr = data; this.flush(); });
|
|
49
57
|
|
package/lib/Terminal.js
CHANGED
|
@@ -133,6 +133,8 @@ class Terminal {
|
|
|
133
133
|
this._titleListeners = [];
|
|
134
134
|
this._mouseButtonDown = null;
|
|
135
135
|
|
|
136
|
+
this._mobileInputElement = null;
|
|
137
|
+
this._onMobileInputClick = null;
|
|
136
138
|
this._typeQueue = '';
|
|
137
139
|
this._typeTimer = null;
|
|
138
140
|
this._isHandlingInput = false;
|
|
@@ -872,14 +874,28 @@ class Terminal {
|
|
|
872
874
|
if (typeof document === 'undefined' || !this._el) return;
|
|
873
875
|
const input = document.createElement('input');
|
|
874
876
|
input.type = 'text';
|
|
875
|
-
input.style.position = '
|
|
876
|
-
input.style.
|
|
877
|
+
input.style.position = 'fixed';
|
|
878
|
+
input.style.top = '0';
|
|
879
|
+
input.style.left = '0';
|
|
880
|
+
input.style.width = '0';
|
|
881
|
+
input.style.height = '0';
|
|
882
|
+
input.style.opacity = '0';
|
|
883
|
+
input.style.pointerEvents = 'none';
|
|
884
|
+
input.style.zIndex = '-1';
|
|
885
|
+
input.setAttribute('aria-hidden', 'true');
|
|
886
|
+
input.setAttribute('tabindex', '-1');
|
|
877
887
|
this._el.appendChild(input);
|
|
888
|
+
this._mobileInputElement = input;
|
|
878
889
|
this._mobileInputBuffer = '';
|
|
879
890
|
|
|
880
|
-
this.
|
|
881
|
-
|
|
882
|
-
|
|
891
|
+
this._onMobileInputClick = (e) => {
|
|
892
|
+
// Avoid stealing focus when clicking hyperlinks
|
|
893
|
+
if (e && e.target && e.target.tagName === 'A') return;
|
|
894
|
+
if (typeof input.focus === 'function') {
|
|
895
|
+
input.focus({ preventScroll: true });
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
this._el.addEventListener('click', this._onMobileInputClick);
|
|
883
899
|
|
|
884
900
|
input.addEventListener('keypress', e => {
|
|
885
901
|
if (e.key === 'Enter') {
|
|
@@ -931,6 +947,17 @@ class Terminal {
|
|
|
931
947
|
if (this._onKeyDown) window.removeEventListener('keydown', this._onKeyDown);
|
|
932
948
|
if (this._onPaste) window.removeEventListener('paste', this._onPaste);
|
|
933
949
|
}
|
|
950
|
+
if (this._mobileInputElement) {
|
|
951
|
+
if (this._onMobileInputClick && this._el && typeof this._el.removeEventListener === 'function') {
|
|
952
|
+
this._el.removeEventListener('click', this._onMobileInputClick);
|
|
953
|
+
}
|
|
954
|
+
if (this._mobileInputElement.parentNode) {
|
|
955
|
+
this._mobileInputElement.parentNode.removeChild(this._mobileInputElement);
|
|
956
|
+
} else if (typeof this._mobileInputElement.remove === 'function') {
|
|
957
|
+
this._mobileInputElement.remove();
|
|
958
|
+
}
|
|
959
|
+
this._mobileInputElement = null;
|
|
960
|
+
}
|
|
934
961
|
this._dataListeners = [];
|
|
935
962
|
this._resizeListeners = [];
|
|
936
963
|
this._titleListeners = [];
|
package/package.json
CHANGED
package/test/scripts.test.js
CHANGED
|
@@ -130,6 +130,35 @@ describe('shell script execution', () => {
|
|
|
130
130
|
expect(errors.length).toBeGreaterThan(0);
|
|
131
131
|
expect(exitCode).toBeGreaterThan(0);
|
|
132
132
|
});
|
|
133
|
+
|
|
134
|
+
it('passes positional parameters to a script', async () => {
|
|
135
|
+
const shell = await createShell({
|
|
136
|
+
filesystem: {
|
|
137
|
+
scripts: {
|
|
138
|
+
'args.sh': '#!/bin/sh\necho 1: $1\necho 2: $2\necho count: $#\necho all: $@\n'
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
permissions: { '/scripts/args.sh': 0o755 }
|
|
142
|
+
});
|
|
143
|
+
const { output } = await run(shell, '/scripts/args.sh "hello world" test');
|
|
144
|
+
expect(output).toContain('1: hello world');
|
|
145
|
+
expect(output).toContain('2: test');
|
|
146
|
+
expect(output).toContain('count: 2');
|
|
147
|
+
expect(output).toContain('all: hello world test');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('forwards "$@" to subcommands within a script', async () => {
|
|
151
|
+
const shell = await createShell({
|
|
152
|
+
filesystem: {
|
|
153
|
+
scripts: {
|
|
154
|
+
'forward.sh': '#!/bin/sh\necho "$@"\n'
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
permissions: { '/scripts/forward.sh': 0o755 }
|
|
158
|
+
});
|
|
159
|
+
const { output } = await run(shell, '/scripts/forward.sh "quoted string"');
|
|
160
|
+
expect(output).toContain('quoted string');
|
|
161
|
+
});
|
|
133
162
|
});
|
|
134
163
|
|
|
135
164
|
// ---------------------------------------------------------------------------
|
package/test/terminal.test.js
CHANGED
|
@@ -39,6 +39,12 @@ function createMockDom() {
|
|
|
39
39
|
if (!this._listeners[ev]) this._listeners[ev] = [];
|
|
40
40
|
this._listeners[ev].push(fn);
|
|
41
41
|
},
|
|
42
|
+
removeEventListener(ev, fn) {
|
|
43
|
+
const list = this._listeners[ev];
|
|
44
|
+
if (!list) return;
|
|
45
|
+
const i = list.indexOf(fn);
|
|
46
|
+
if (i !== -1) list.splice(i, 1);
|
|
47
|
+
},
|
|
42
48
|
dispatchEvent(ev, payload = {}) {
|
|
43
49
|
const fns = this._listeners[ev] || [];
|
|
44
50
|
for (const fn of fns) fn(payload);
|
|
@@ -832,4 +838,49 @@ describe('Output Typing Animation Suppression', () => {
|
|
|
832
838
|
term.reset();
|
|
833
839
|
}
|
|
834
840
|
});
|
|
841
|
+
|
|
842
|
+
describe('mobileInput and destroy cleanup', () => {
|
|
843
|
+
it('anchors off-screen input at fixed (0, 0) and uses preventScroll', () => {
|
|
844
|
+
const el = document.createElement('div');
|
|
845
|
+
const term = new Terminal({
|
|
846
|
+
el,
|
|
847
|
+
Shell: false,
|
|
848
|
+
mobileInput: 'click'
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
const input = term._mobileInputElement;
|
|
852
|
+
expect(input).toBeDefined();
|
|
853
|
+
expect(input.style.position).toBe('fixed');
|
|
854
|
+
expect(input.style.top).toBe('0');
|
|
855
|
+
expect(input.style.left).toBe('0');
|
|
856
|
+
expect(input.style.width).toBe('0');
|
|
857
|
+
expect(input.style.height).toBe('0');
|
|
858
|
+
expect(input.style.opacity).toBe('0');
|
|
859
|
+
expect(input.style.pointerEvents).toBe('none');
|
|
860
|
+
expect(input.style.zIndex).toBe('-1');
|
|
861
|
+
expect(input['aria-hidden']).toBe('true');
|
|
862
|
+
expect(input.tabindex).toBe('-1');
|
|
863
|
+
|
|
864
|
+
let focusedWith = null;
|
|
865
|
+
input.focus = (opts) => {
|
|
866
|
+
focusedWith = opts;
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
// Clicking terminal focuses with preventScroll: true
|
|
870
|
+
el.dispatchEvent('click', { target: el });
|
|
871
|
+
expect(focusedWith).toEqual({ preventScroll: true });
|
|
872
|
+
|
|
873
|
+
// Clicking a link does not trigger focus
|
|
874
|
+
focusedWith = null;
|
|
875
|
+
const link = document.createElement('a');
|
|
876
|
+
el.dispatchEvent('click', { target: link });
|
|
877
|
+
expect(focusedWith).toBeNull();
|
|
878
|
+
|
|
879
|
+
// Destroy removes input from DOM and cleans up
|
|
880
|
+
expect(el.children).toContain(input);
|
|
881
|
+
term.destroy();
|
|
882
|
+
expect(el.children).not.toContain(input);
|
|
883
|
+
expect(term._mobileInputElement).toBeNull();
|
|
884
|
+
});
|
|
885
|
+
});
|
|
835
886
|
});
|