forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-tty-get-color-depth.js
More file actions
36 lines (27 loc) · 931 Bytes
/
test-tty-get-color-depth.js
File metadata and controls
36 lines (27 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const common = require('../common');
const assert = require('assert').strict;
/* eslint-disable no-restricted-properties */
const { WriteStream } = require('tty');
const fd = common.getTTYfd();
const writeStream = new WriteStream(fd);
{
const depth = writeStream.getColorDepth();
assert.equal(typeof depth, 'number');
assert(depth >= 1 && depth <= 24);
if (depth === 1) {
// Terminal does not support colors, compare to a value that would.
assert.notEqual(writeStream.getColorDepth({ COLORTERM: '1' }), depth);
} else {
// Terminal supports colors, compare to a value that would not.
assert.notEqual(writeStream.getColorDepth({ TERM: 'dumb' }), depth);
}
}
// Deactivate colors
{
const tmp = process.env.NODE_DISABLE_COLORS;
process.env.NODE_DISABLE_COLORS = 1;
const depth = writeStream.getColorDepth();
assert.equal(depth, 1);
process.env.NODE_DISABLE_COLORS = tmp;
}