writeStream.getColorDepth([env])
返回:
1
表示支持 2 种颜色,4
表示支持 16 种颜色,8
表示支持 256 种颜色,24
表示支持 16,777,216 种颜色。
使用此函数可以检测终端支持的颜色数。
鉴于终端中颜色的特性,可能存在假的正数或假的负数。
这取决于进程信息与环境变量(可能会隐瞒使用的终端)。
可以传入 env
对象来模拟特定终端的使用。
这对于检查特定环境设置的行为很有用。
如果要强制执行特定的颜色支持,则使用以下的环境设置之一。
- 2 种颜色:
FORCE_COLOR = 0
(禁用颜色) - 16 种颜色:
FORCE_COLOR = 1
- 256 种颜色:
FORCE_COLOR = 2
- 16,777,216 种颜色:
FORCE_COLOR = 3
也可以使用 NO_COLOR
和 NODE_DISABLE_COLORS
环境变量来禁用颜色支持。
env
<Object> An object containing the environment variables to check. This enables simulating the usage of a specific terminal. Default:process.env
.- Returns: <number>
Returns:
1
for 2,4
for 16,8
for 256,24
for 16,777,216
colors supported.
Use this to determine what colors the terminal supports. Due to the nature of
colors in terminals it is possible to either have false positives or false
negatives. It depends on process information and the environment variables that
may lie about what terminal is used.
It is possible to pass in an env
object to simulate the usage of a specific
terminal. This can be useful to check how specific environment settings behave.
To enforce a specific color support, use one of the below environment settings.
- 2 colors:
FORCE_COLOR = 0
(Disables colors) - 16 colors:
FORCE_COLOR = 1
- 256 colors:
FORCE_COLOR = 2
- 16,777,216 colors:
FORCE_COLOR = 3
Disabling color support is also possible by using the NO_COLOR
and
NODE_DISABLE_COLORS
environment variables.