From ee2e6933403811d398540e0e8275b2d216546dd8 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Fri, 19 Jul 2024 12:39:05 +0200 Subject: fix(node): support `tty.hasColors()` and `tty.getColorDepth()` (#24619) This PR adds support for [`tty.WriteStream.prototype.hasColors()`](https://nodejs.org/api/tty.html#writestreamhascolorscount-env) and [`tty.WriteStream.prototype.getColorDepth()`](https://nodejs.org/api/tty.html#writestreamgetcolordepthenv). I couldn't find any usage on GitHub which passes parameters to it. Therefore I've skipped adding support for the `env` parameter to keep our snapshot size small. Based on https://github.com/denoland/deno_terminal/pull/3 Fixes https://github.com/denoland/deno/issues/24616 --- tests/unit_node/tty_test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/unit_node/tty_test.ts b/tests/unit_node/tty_test.ts index 39ab4fe17..cde05b9ff 100644 --- a/tests/unit_node/tty_test.ts +++ b/tests/unit_node/tty_test.ts @@ -3,6 +3,7 @@ import { assert } from "@std/assert/mod.ts"; import { isatty } from "node:tty"; +import tty from "node:tty"; import process from "node:process"; Deno.test("[node/tty isatty] returns true when fd is a tty, false otherwise", () => { @@ -34,3 +35,11 @@ Deno.test("[node/tty WriteStream.isTTY] returns true when fd is a tty", () => { assert(Deno.stdin.isTerminal() === process.stdin.isTTY); assert(Deno.stdout.isTerminal() === process.stdout.isTTY); }); + +Deno.test("[node/tty WriteStream.hasColors] returns true when colors are supported", () => { + assert(tty.WriteStream.prototype.hasColors() === !Deno.noColor); +}); + +Deno.test("[node/tty WriteStream.getColorDepth] returns current terminal color depth", () => { + assert([1, 4, 8, 24].includes(tty.WriteStream.prototype.getColorDepth())); +}); -- cgit v1.2.3