1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00

fix(node/tty): fix tty.WriteStream.hasColor with different args (#25094)

The check in `tty.WriteStream.prototype.hasColors()` was incorrect
leading to the
[`yoctocolors`](https://github.com/sindresorhus/yoctocolors) package not
printing any colors.

Fixes https://github.com/denoland/deno/issues/24407
This commit is contained in:
Marvin Hagemeister 2024-08-19 17:13:09 +02:00 committed by GitHub
parent c94c5cddb1
commit 48701c19f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -113,7 +113,10 @@ export class WriteStream extends Socket {
* @returns {boolean}
*/
hasColors(count, env) {
if (env === undefined && typeof count === "object") {
if (
env === undefined &&
(count === undefined || typeof count === "object" && count !== null)
) {
env = count;
count = 16;
}

View file

@ -38,6 +38,10 @@ Deno.test("[node/tty WriteStream.isTTY] returns true when fd is a tty", () => {
Deno.test("[node/tty WriteStream.hasColors] returns true when colors are supported", () => {
assert(tty.WriteStream.prototype.hasColors() === !Deno.noColor);
assert(tty.WriteStream.prototype.hasColors({}) === !Deno.noColor);
assert(tty.WriteStream.prototype.hasColors(1));
assert(tty.WriteStream.prototype.hasColors(1, {}));
});
Deno.test("[node/tty WriteStream.getColorDepth] returns current terminal color depth", () => {