自定义 util.inspect 颜色
¥Customizing util.inspect
colors
util.inspect
的颜色输出(如果启用)可通过 util.inspect.styles
和 util.inspect.colors
属性全局地自定义。
¥Color output (if enabled) of util.inspect
is customizable globally
via the util.inspect.styles
and util.inspect.colors
properties.
util.inspect.styles
是将样式名称与来自 util.inspect.colors
的颜色相关联的映射。
¥util.inspect.styles
is a map associating a style name to a color from
util.inspect.colors
.
默认的样式和相关的颜色为:
¥The default styles and associated colors are:
-
bigint
:yellow
-
boolean
:yellow
-
date
:magenta
-
module
:underline
-
name
:(没有样式)¥
name
: (no styling) -
null
:bold
-
number
:yellow
-
regexp
:red
-
special
:cyan
(例如,Proxies
)¥
special
:cyan
(e.g.,Proxies
) -
string
:green
-
symbol
:green
-
undefined
:grey
颜色样式使用 ANSI 控制代码,可能并非所有终端都支持。要验证颜色支持,则使用 tty.hasColors()
。
¥Color styling uses ANSI control codes that may not be supported on all
terminals. To verify color support use tty.hasColors()
.
下面列出了预定义的控制代码(分组为 "修饰符"、"前景色" 和 "背景颜色")。
¥Predefined control codes are listed below (grouped as "Modifiers", "Foreground colors", and "Background colors").