从Cucumber输出“管道”时的文字着色

时间:2012-05-16 12:16:33

标签: ruby

我尝试通过Ruby管道命令行命令的输出。 它工作正常,但缺少着色。 我怎样才能保留着色?

这就是我的代码:

cmd = "cucumber #{ARGV.join(" ")}"
IO.popen(cmd) do |io|
  io.each { |s| print s }
end

更新: 问题的前提是错误的 - IO.popen 确实保留颜色。

1 个答案:

答案 0 :(得分:2)

使用-c选项运行黄瓜。否则,黄瓜会确定终端(管道)不支持着色,如果未明确强制使用-c,则会丢弃它。

https://github.com/cucumber/cucumber/blob/master/lib/cucumber/cli/options.rb#L211

...
opts.on("-c", "--[no-]color",
        "Whether or not to use ANSI color in the output. Cucumber decides",
        "based on your platform and the output destination if not specified.")
...