Skip to content

Commit

Permalink
fix(node/tty): fix tty.WriteStream.hasColor with different args (#2…
Browse files Browse the repository at this point in the history
…5094)

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

Fixes #24407
  • Loading branch information
marvinhagemeister authored Aug 19, 2024
1 parent c94c5cd commit 48701c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ext/node/polyfills/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_node/tty_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 48701c1

Please sign in to comment.