From 48701c19f8b2661c7e2cd997e62070d74baa86d0 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 19 Aug 2024 17:13:09 +0200 Subject: 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 --- ext/node/polyfills/tty.js | 5 ++++- tests/unit_node/tty_test.ts | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/tty.js b/ext/node/polyfills/tty.js index 2e8ecc8e1..e906c5f67 100644 --- a/ext/node/polyfills/tty.js +++ b/ext/node/polyfills/tty.js @@ -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; } diff --git a/tests/unit_node/tty_test.ts b/tests/unit_node/tty_test.ts index ab3193f4a..7f0395682 100644 --- a/tests/unit_node/tty_test.ts +++ b/tests/unit_node/tty_test.ts @@ -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", () => { -- cgit v1.2.3