20

在使用 npm in 时M-x term,它会生成这样的颜色消息(即使使用 -q):

反色

信息来自what-cursor-position

There are text properties here:
font-lock-face       (:foreground "red3" :background "black" :inverse-video nil)
fontified            t

它很难看,而且在其他主题中也很难阅读,是否可以即时更改颜色?例如,更改匹配的文本颜色npm httpnpm ERR!

谢谢。

4

2 回答 2

33

您可以使用以下命令在 npm 中禁用颜色:

npm config set color false

这并不能完全回答您的问题,因为它不是在术语模式下覆盖 ANSI 颜色的方法,但它会解决您的问题,因为 npm 输出将不再丑陋且难以阅读。

于 2013-12-20T19:25:10.323 回答
3

我为 davidchambers/dotfiles#1 创建了一个npm包装。这是完整的代码:

__strip_background_colors() {
  local output="$(sed $'s:\x1B\[4[0-9]m::g')"
  [[ -n $output ]] && printf %s%s "$output" "$1"
}

npm() {
  # Strip the visually offensive background colours from npm's output,
  # leaving the foreground colours intact.
  NPM_CONFIG_COLOR=always "$(which npm)" "$@" \
    1> >(__strip_background_colors $'\n' >&1) \
    2> >(__strip_background_colors '' >&2)
}

它去除了令人反感的背景颜色,同时保留了相当漂亮的前景色。:)

于 2014-04-26T06:52:44.717 回答