writeStream.getColorDepth([env])
Returns:
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.