writeStream.hasColors([count][, env])


  • count <integer> 请求的颜色数量(最少 2 种)。 **默认值:**16。
  • env <Object> 一个包含要检查的环境变量的对象。这可以模拟使用特定终端的情况。默认值: process.env
  • 返回:<boolean>

如果 writeStream 支持的颜色至少与 count 中提供的数量一样多,则返回 true。最低支持为 2(黑色和白色)。

【Returns true if the writeStream supports at least as many colors as provided in count. Minimum support is 2 (black and white).】

这与 writeStream.getColorDepth() 中描述的具有相同的误报和漏报。

【This has the same false positives and negatives as described in writeStream.getColorDepth().】

process.stdout.hasColors();
// Returns true or false depending on if `stdout` supports at least 16 colors.
process.stdout.hasColors(256);
// Returns true or false depending on if `stdout` supports at least 256 colors.
process.stdout.hasColors({ TMUX: '1' });
// Returns true.
process.stdout.hasColors(2 ** 24, { TMUX: '1' });
// Returns false (the environment setting pretends to support 2 ** 8 colors).