aboutsummaryrefslogtreecommitdiff
path: root/src/js/node/tty.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
commit7458b969c5d9971e89d187b687e1924e78da427e (patch)
treeee3dbf95c728cf407bf49a27826b541e9264a8bd /src/js/node/tty.js
parentd4a2c29131ec154f5e4db897d4deedab2002cbc4 (diff)
parente91436e5248d947b50f90b4a7402690be8a41f39 (diff)
downloadbun-7458b969c5d9971e89d187b687e1924e78da427e.tar.gz
bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.zst
bun-7458b969c5d9971e89d187b687e1924e78da427e.zip
Merge branch 'main' into postinstall_3
Diffstat (limited to 'src/js/node/tty.js')
-rw-r--r--src/js/node/tty.js39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/js/node/tty.js b/src/js/node/tty.js
index d5645c6da..6e138b0cf 100644
--- a/src/js/node/tty.js
+++ b/src/js/node/tty.js
@@ -1,36 +1,43 @@
const { ttySetMode, isatty, getWindowSize: _getWindowSize } = $lazy("tty");
+// primordials
+const NumberIsInteger = Number.isInteger;
+
function ReadStream(fd) {
if (!(this instanceof ReadStream)) return new ReadStream(fd);
if (fd >> 0 !== fd || fd < 0) throw new RangeError("fd must be a positive integer");
- const stream = require("node:fs").ReadStream.call(this, "", {
+ const stream = require("node:fs").ReadStream.$call(this, "", {
fd,
});
+ Object.setPrototypeOf(stream, ReadStream.prototype);
stream.isRaw = false;
- stream.isTTY = isatty(stream.fd);
+ stream.isTTY = true;
+
+ $assert(stream instanceof ReadStream);
return stream;
}
Object.defineProperty(ReadStream, "prototype", {
get() {
- const Real = require("node:fs").ReadStream.prototype;
+ const Prototype = Object.create(require("node:fs").ReadStream.prototype);
- Object.defineProperty(ReadStream, "prototype", { value: Real });
- ReadStream.prototype.setRawMode = function (flag) {
+ Prototype.setRawMode = function (flag) {
const mode = flag ? 1 : 0;
const err = ttySetMode(this.fd, mode);
if (err) {
- this.emit("error", new Error("setRawMode failed with errno:", err));
+ this.emit("error", new Error("setRawMode failed with errno: " + err));
return this;
}
this.isRaw = flag;
return this;
};
- return Real;
+ Object.defineProperty(ReadStream, "prototype", { value: Prototype });
+
+ return Prototype;
},
enumerable: true,
configurable: true,
@@ -95,7 +102,7 @@ function WriteStream(fd) {
if (!(this instanceof WriteStream)) return new WriteStream(fd);
if (fd >> 0 !== fd || fd < 0) throw new RangeError("fd must be a positive integer");
- const stream = require("node:fs").WriteStream.call(this, "", {
+ const stream = require("node:fs").WriteStream.$call(this, "", {
fd,
});
@@ -185,7 +192,7 @@ Object.defineProperty(WriteStream, "prototype", {
// Lazy load for startup performance.
if (OSRelease === undefined) {
const { release } = require("node:os");
- OSRelease = StringPrototypeSplit(release(), ".");
+ OSRelease = release().split(".");
}
// Windows 10 build 10586 is the first Windows release that supports 256
// colors. Windows 10 build 14931 is the first release that supports
@@ -216,14 +223,12 @@ Object.defineProperty(WriteStream, "prototype", {
}
if ("TEAMCITY_VERSION" in env) {
- return RegExpPrototypeExec(/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/, env.TEAMCITY_VERSION) !== null
- ? COLORS_16
- : COLORS_2;
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? COLORS_16 : COLORS_2;
}
switch (env.TERM_PROGRAM) {
case "iTerm.app":
- if (!env.TERM_PROGRAM_VERSION || RegExpPrototypeExec(/^[0-2]\./, env.TERM_PROGRAM_VERSION) !== null) {
+ if (!env.TERM_PROGRAM_VERSION || /^[0-2]\./.test(env.TERM_PROGRAM_VERSION)) {
return COLORS_256;
}
return COLORS_16m;
@@ -239,16 +244,16 @@ Object.defineProperty(WriteStream, "prototype", {
}
if (env.TERM) {
- if (RegExpPrototypeExec(/^xterm-256/, env.TERM) !== null) {
+ if (/^xterm-256/.test(env.TERM) !== null) {
return COLORS_256;
}
- const termEnv = StringPrototypeToLowerCase(env.TERM);
+ const termEnv = env.TERM.toLowerCase();
if (TERM_ENVS[termEnv]) {
return TERM_ENVS[termEnv];
}
- if (ArrayPrototypeSome(TERM_ENVS_REG_EXP, term => RegExpPrototypeExec(term, termEnv) !== null)) {
+ if (TERM_ENVS_REG_EXP.some(term => term.test(termEnv))) {
return COLORS_16;
}
}
@@ -286,7 +291,7 @@ Object.defineProperty(WriteStream, "prototype", {
var validateInteger = (value, name, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) => {
if (typeof value !== "number") throw new ERR_INVALID_ARG_TYPE(name, "number", value);
- if (!Number.isInteger(value)) throw new ERR_OUT_OF_RANGE(name, "an integer", value);
+ if (!NumberIsInteger(value)) throw new ERR_OUT_OF_RANGE(name, "an integer", value);
if (value < min || value > max) throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
};