2012-05-16 55 views
1

我嘗試通過Ruby從命令行命令輸出輸出。 它工作正常,但缺少着色。 我該如何保存顏色?從Cucumber輸出「管道」輸出時的文字着色

這是我的代碼如下所示:

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

更新: 這個問題的前提是錯誤的 - IO.popen 確實保留的顏色。

回答

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.") 
... 
+0

真棒。我剛剛更新了標題並添加了對該問題的評論。 – jonasmaturana