summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/tty.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/tty.js')
-rw-r--r--ext/node/polyfills/tty.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/ext/node/polyfills/tty.js b/ext/node/polyfills/tty.js
index 3a84a1f94..2e8ecc8e1 100644
--- a/ext/node/polyfills/tty.js
+++ b/ext/node/polyfills/tty.js
@@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+import { op_bootstrap_color_depth } from "ext:core/ops";
import { core, primordials } from "ext:core/mod.js";
const {
Error,
@@ -105,6 +106,32 @@ export class WriteStream extends Socket {
this.rows = rows;
this.isTTY = true;
}
+
+ /**
+ * @param {number | Record<string, string>} [count]
+ * @param {Record<string, string>} [env]
+ * @returns {boolean}
+ */
+ hasColors(count, env) {
+ if (env === undefined && typeof count === "object") {
+ env = count;
+ count = 16;
+ }
+
+ const depth = this.getColorDepth(env);
+ return count <= 2 ** depth;
+ }
+
+ /**
+ * @param {Record<string, string} [env]
+ * @returns {1 | 4 | 8 | 24}
+ */
+ getColorDepth(_env) {
+ // TODO(@marvinhagemeister): Ignore env parameter.
+ // Haven't seen it used anywhere, seems more done
+ // to make testing easier in Node
+ return op_bootstrap_color_depth();
+ }
}
export { isatty };