summaryrefslogtreecommitdiff
path: root/test/pseudo-tty
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-01-19 15:37:38 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-05 18:37:39 +0100
commitd4fdec6b6593659cb38e1db9c8083d4fde9bcacb (patch)
treeecaf80b2517373e0cdb264c945209b7d12f65766 /test/pseudo-tty
parenta52c1ead0221a0c913d55d86ddddbe2ff3d04d5b (diff)
downloadnode-new-d4fdec6b6593659cb38e1db9c8083d4fde9bcacb.tar.gz
tty: add hasColors function
This adds a small wrapper around the `getColorDepth` function to check if the stream supports at least a specific amount of colors. This is convenient as the other API is not as straight forward and most use cases likely only want to know if a specific amount of colors is supported or not. PR-URL: https://github.com/nodejs/node/pull/26247 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'test/pseudo-tty')
-rw-r--r--test/pseudo-tty/test-tty-color-support.js (renamed from test/pseudo-tty/test-tty-get-color-depth.js)22
-rw-r--r--test/pseudo-tty/test-tty-color-support.out (renamed from test/pseudo-tty/test-tty-get-color-depth.out)0
2 files changed, 22 insertions, 0 deletions
diff --git a/test/pseudo-tty/test-tty-get-color-depth.js b/test/pseudo-tty/test-tty-color-support.js
index 14151ec3fb..b5bc3aca24 100644
--- a/test/pseudo-tty/test-tty-get-color-depth.js
+++ b/test/pseudo-tty/test-tty-color-support.js
@@ -12,8 +12,26 @@ const writeStream = new WriteStream(fd);
const depth = writeStream.getColorDepth();
assert.strictEqual(typeof depth, 'number');
assert(depth >= 1 && depth <= 24);
+
+ const support = writeStream.hasColors();
+ assert.strictEqual(support, depth !== 1);
}
+// Validate invalid input.
+[true, null, () => {}, Symbol(), 5n].forEach((input) => {
+ assert.throws(
+ () => writeStream.hasColors(input),
+ { code: 'ERR_INVALID_ARG_TYPE' }
+ );
+});
+
+[-1, 1].forEach((input) => {
+ assert.throws(
+ () => writeStream.hasColors(input),
+ { code: 'ERR_OUT_OF_RANGE' }
+ );
+});
+
// Check different environment variables.
[
[{ COLORTERM: '1' }, 4],
@@ -54,6 +72,10 @@ const writeStream = new WriteStream(fd);
`i: ${i}, expected: ${depth}, ` +
`actual: ${actual}, env: ${inspect(env)}`
);
+ const colors = 2 ** actual;
+ assert(writeStream.hasColors(colors, env));
+ assert(!writeStream.hasColors(colors + 1, env));
+ assert(depth >= 4 ? writeStream.hasColors(env) : !writeStream.hasColors(env));
});
// OS settings
diff --git a/test/pseudo-tty/test-tty-get-color-depth.out b/test/pseudo-tty/test-tty-color-support.out
index e69de29bb2..e69de29bb2 100644
--- a/test/pseudo-tty/test-tty-get-color-depth.out
+++ b/test/pseudo-tty/test-tty-color-support.out