如何在Emacs术语模式下阻止npm的彩色输出看起来很难看?

时间:2013-12-20 15:24:35

标签: emacs emacs-faces

M-x term中使用npm时,会生成这样的颜色信息(即使使用-q):

inverse color

来自what-cursor-position

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

它很丑陋,在其他主题中也难以阅读,是否有可能在飞行中改变颜色?例如,更改与npm httpnpm ERR!

匹配的文字颜色

感谢。

2 个答案:

答案 0 :(得分:21)

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

npm config set color false

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

答案 1 :(得分: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)
}

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

相关问题