brsh 2.2.0 → 2.2.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/bin/brsh-shell.js +8 -0
- package/dist/shell.es.js +49 -23
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +2 -2
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.es.js +49 -23
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +2 -2
- package/dist/terminal.min.js.map +1 -1
- package/lib/ScriptCommand.js +67 -38
- package/lib/local/read.js +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.2.1](https://github.com/eliotstocker/Brsh-JS/compare/v2.2.0...v2.2.1) (2026-05-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* script flushing and input issues ([7c5d583](https://github.com/eliotstocker/Brsh-JS/commit/7c5d583f23042c2457cbec967335c658e51916cc))
|
|
7
|
+
|
|
1
8
|
# [2.2.0](https://github.com/eliotstocker/Brsh-JS/compare/v2.1.5...v2.2.0) (2026-05-23)
|
|
2
9
|
|
|
3
10
|
|
package/bin/brsh-shell.js
CHANGED
|
@@ -63,3 +63,11 @@ function ask() {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
rl.on('close', () => { if (!destroyed) process.exit(0); });
|
|
66
|
+
|
|
67
|
+
// Forward typed lines to commands waiting for input (e.g. `read`)
|
|
68
|
+
rl.on('line', function(line) {
|
|
69
|
+
if (shell.runningCommand && shell.runningCommand.captureInput) {
|
|
70
|
+
for (const char of line) { shell.onInput(char); }
|
|
71
|
+
shell.onInput('Enter');
|
|
72
|
+
}
|
|
73
|
+
});
|
package/dist/shell.es.js
CHANGED
|
@@ -950,7 +950,7 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
950
950
|
super(t, n), this.script = e, this.source = r;
|
|
951
951
|
}
|
|
952
952
|
get captureInput() {
|
|
953
|
-
return
|
|
953
|
+
return !!(this.sandbox && this.sandbox.runningCommand && this.sandbox.runningCommand.captureInput);
|
|
954
954
|
}
|
|
955
955
|
onInput(e) {
|
|
956
956
|
this.sandbox && this.sandbox.onInput(e);
|
|
@@ -963,7 +963,11 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
963
963
|
this.sandbox = new r.shell({
|
|
964
964
|
cwd: this.context.fs.cwd,
|
|
965
965
|
...e
|
|
966
|
-
}), this.sandbox.context.source(this.context), this.sandbox.on("stdOut", (e) =>
|
|
966
|
+
}), this.sandbox.context.source(this.context), this.sandbox.on("stdOut", (e) => {
|
|
967
|
+
this.stdOut = e, this.flush();
|
|
968
|
+
}), this.sandbox.on("stdErr", (e) => {
|
|
969
|
+
this.stdErr = e, this.flush();
|
|
970
|
+
}), this._scriptFunctions = {};
|
|
967
971
|
let t = this.script.split(/\r?\n/);
|
|
968
972
|
if (!a(t[0])) {
|
|
969
973
|
let e = t[0].startsWith("#!") ? t[0].slice(2).split(/\s/)[0] : t[0];
|
|
@@ -1018,29 +1022,37 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
1018
1022
|
return t;
|
|
1019
1023
|
}
|
|
1020
1024
|
_parseIf(e, t) {
|
|
1021
|
-
let n = e
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1025
|
+
let n = (e) => e.replace(/^(?:if|elif)\s+/, "").replace(/\s*;\s*then\s*$/, "").replace(/\s+then\s*$/, "").trim(), r = [{
|
|
1026
|
+
condition: n(e[t].trim()),
|
|
1027
|
+
bodyLines: []
|
|
1028
|
+
}], i = [], a = r[0], o = !1, s = 1, c = t + 1;
|
|
1029
|
+
for (c < e.length && e[c].trim() === "then" && c++; c < e.length;) {
|
|
1030
|
+
let t = e[c].trim();
|
|
1031
|
+
if ((t.startsWith("if ") || t === "if") && s++, t === "fi" && (s--, s === 0)) {
|
|
1032
|
+
c++;
|
|
1028
1033
|
break;
|
|
1029
1034
|
}
|
|
1030
|
-
if (
|
|
1031
|
-
|
|
1035
|
+
if (s === 1 && t.startsWith("elif ")) {
|
|
1036
|
+
let i = {
|
|
1037
|
+
condition: n(t),
|
|
1038
|
+
bodyLines: []
|
|
1039
|
+
};
|
|
1040
|
+
r.push(i), a = i, c++, c < e.length && e[c].trim() === "then" && c++;
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
if (s === 1 && t === "else") {
|
|
1044
|
+
o = !0, c++;
|
|
1032
1045
|
continue;
|
|
1033
1046
|
}
|
|
1034
|
-
o ?
|
|
1047
|
+
o ? i.push(e[c]) : a.bodyLines.push(e[c]), c++;
|
|
1035
1048
|
}
|
|
1036
1049
|
return {
|
|
1037
1050
|
node: {
|
|
1038
1051
|
type: "if",
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
elseLines: a
|
|
1052
|
+
clauses: r,
|
|
1053
|
+
elseLines: i
|
|
1042
1054
|
},
|
|
1043
|
-
consumed:
|
|
1055
|
+
consumed: c - t
|
|
1044
1056
|
};
|
|
1045
1057
|
}
|
|
1046
1058
|
_parseWhile(e, t) {
|
|
@@ -1096,8 +1108,16 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
1096
1108
|
return t;
|
|
1097
1109
|
}
|
|
1098
1110
|
run() {
|
|
1099
|
-
|
|
1100
|
-
|
|
1111
|
+
let e = this.arguments.map((e, t) => ({
|
|
1112
|
+
key: String(t + 1),
|
|
1113
|
+
prev: r.sandbox.context.getVar(String(t + 1))
|
|
1114
|
+
}));
|
|
1115
|
+
this.arguments.forEach((e, t) => r.sandbox.context.setVar(String(t + 1), e));
|
|
1116
|
+
let t = () => e.forEach(({ key: e, prev: t }) => t ? r.sandbox.context.setVar(e, t) : r.sandbox.context.unsetVar(e));
|
|
1117
|
+
return r._executeFunctionBody(n).then(() => {
|
|
1118
|
+
t();
|
|
1119
|
+
}).catch((e) => {
|
|
1120
|
+
if (t(), e && e.__type === "return") {
|
|
1101
1121
|
this.exitCode = e.code;
|
|
1102
1122
|
return;
|
|
1103
1123
|
}
|
|
@@ -1120,10 +1140,12 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
1120
1140
|
return e.type === "if" ? this._executeIf(e) : e.type === "while" ? this._executeWhile(e) : e.type === "for" ? this._executeFor(e) : e.type === "case" ? this._executeCase(e) : Promise.resolve();
|
|
1121
1141
|
}
|
|
1122
1142
|
_executeIf(e) {
|
|
1123
|
-
|
|
1124
|
-
if (
|
|
1125
|
-
|
|
1126
|
-
|
|
1143
|
+
let t = (n) => {
|
|
1144
|
+
if (n >= e.clauses.length) return e.elseLines.length > 0 ? this._executeNodes(this._parseLines(e.elseLines)) : Promise.resolve();
|
|
1145
|
+
let r = e.clauses[n];
|
|
1146
|
+
return this.sandbox.onCommand(r.condition, !1).then(() => this.sandbox.lastCode === 0 ? this._executeNodes(this._parseLines(r.bodyLines)) : t(n + 1));
|
|
1147
|
+
};
|
|
1148
|
+
return t(0);
|
|
1127
1149
|
}
|
|
1128
1150
|
_executeWhile(e) {
|
|
1129
1151
|
let t = () => this.sandbox.onCommand(e.condition, !1).then(() => {
|
|
@@ -3846,7 +3868,11 @@ var V, re, H, U, ie, ae, W, oe, se, G, K = e((() => {
|
|
|
3846
3868
|
}));
|
|
3847
3869
|
}
|
|
3848
3870
|
onInput(e) {
|
|
3849
|
-
if (this.inputBuffer ||= "", e.length === 1 && (this.inputBuffer += e),
|
|
3871
|
+
if (this.inputBuffer ||= "", e.length === 1 && (this.inputBuffer += e), e === "Enter") {
|
|
3872
|
+
this.var ? (this.context.setVar(this.var, this.inputBuffer || ""), this.completionCallback()) : this.completionCallback(this.inputBuffer || "");
|
|
3873
|
+
return;
|
|
3874
|
+
}
|
|
3875
|
+
if (this.inputBuffer.length === this.nchars) {
|
|
3850
3876
|
if (this.var) {
|
|
3851
3877
|
this.context.setVar(this.var, this.inputBuffer), this.completionCallback();
|
|
3852
3878
|
return;
|