Skip to content

Commit 8695301

Browse files
lib/tty.js: expose hasColor and getColorDepth directly
1 parent 2caa308 commit 8695301

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/tty.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
getColorDepth,
3636
hasColors
3737
} = require('internal/tty');
38+
const { deprecate } = require('internal/util');
3839

3940
// Lazy loaded for startup performance.
4041
let readline;
@@ -119,9 +120,17 @@ ObjectSetPrototypeOf(WriteStream, net.Socket);
119120

120121
WriteStream.prototype.isTTY = true;
121122

122-
WriteStream.prototype.getColorDepth = getColorDepth;
123+
WriteStream.prototype.getColorDepth = deprecate(
124+
getColorDepth,
125+
'tty.WriteStream.getColorDepth is deprecated. ' +
126+
'Please use tty.getColorDepth instead.',
127+
'DEP0156');
123128

124-
WriteStream.prototype.hasColors = hasColors;
129+
WriteStream.prototype.hasColors = deprecate(
130+
hasColors,
131+
'tty.WriteStream.hasColors is deprecated. ' +
132+
'Please use tty.hasColors instead.',
133+
'DEP0157');
125134

126135
WriteStream.prototype._refreshSize = function() {
127136
const oldCols = this.columns;
@@ -161,4 +170,4 @@ WriteStream.prototype.getWindowSize = function() {
161170
return [this.columns, this.rows];
162171
};
163172

164-
module.exports = { isatty, ReadStream, WriteStream };
173+
module.exports = { isatty, getColorDepth, hasColors, ReadStream, WriteStream };
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const { expectWarning } = require('../common');
4+
const { WriteStream } = require('tty');
5+
6+
expectWarning({
7+
DeprecationWarning: {
8+
DEP0157: 'tty.WriteStream.hasColors is deprecated. ' +
9+
'Please use tty.hasColors instead.',
10+
DEP0156: 'tty.WriteStream.getColorDepth is deprecated. ' +
11+
'Please use tty.getColorDepth instead.'
12+
}
13+
});
14+
15+
const writeStream = WriteStream(1);
16+
17+
writeStream.hasColors();
18+
writeStream.getColorDepth();

0 commit comments

Comments
 (0)