【问题标题】:Disable terminal escape sequences in node.js output在 node.js 输出中禁用终端转义序列
【发布时间】:2014-12-16 08:44:32
【问题描述】:

我在 node.js 上使用 Karma 来运行测试作为构建脚本的一部分。独立运行命令时,如下所示:

但是,当作为构建作业的一部分运行时,它会变成这样:

TestJs:
  node node_modules\karma\bin\karma start lib\Tests.conf.js
  ←[33mWARN [karma]: ←[39mPort 19876 in use
  ←[32mINFO [karma]: ←[39mKarma v0.12.28 server started at http://localhost:19877/
  ←[32mINFO [launcher]: ←[39mStarting browser PhantomJS
  ←[32mINFO [PhantomJS 1.9.8 (Windows 8)]: ←[39mConnected on socket tw-cSawB8PRCSVL-QYsr with id 81276065

这有点难以阅读。显然 Node 本身对将 ANSI 转义序列转换为 Windows 控制台 API 有某种支持,但是在重定向或捕获输出时会丢失(执行 shell 重定向时写入的文件也包含转义序列)。

有没有办法抑制颜色? node --help 提到 $Env:NODE_DISABLE_COLORS,但是,这似乎只适用于 REPL,对我运行脚本没有任何帮助。

【问题讨论】:

    标签: windows node.js ansi-escape


    【解决方案1】:

    没关系,我在 Karma 配置中找到了一行:

    // enable / disable colors in the output (reporters and logs)
    colors: true,
    

    我只是忘记更改了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2011-10-28
      相关资源
      最近更新 更多