ruby-changes:23789
From: nobu <ko1@a...>
Date: Wed, 30 May 2012 10:24:21 +0900 (JST)
Subject: [ruby-changes:23789] nobu:r35840 (trunk): color option
nobu 2012-05-30 10:24:08 +0900 (Wed, 30 May 2012) New Revision: 35840 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35840 Log: color option * bootstraptest/runner.rb, sample/test.rb: add --color option. Modified files: trunk/bootstraptest/runner.rb trunk/sample/test.rb Index: bootstraptest/runner.rb =================================================================== --- bootstraptest/runner.rb (revision 35839) +++ bootstraptest/runner.rb (revision 35840) @@ -61,6 +61,7 @@ @ruby = File.expand_path('miniruby') @verbose = false $stress = false + @color = nil dir = nil quiet = false tests = nil @@ -81,6 +82,9 @@ true when /\A(--stress|-s)/ $stress = true + when /\A--color(?:=(?:always|(auto)|(never)))?\z/ + @color = (!$2 unless $1) + true when /\A(-q|--q(uiet))\z/ quiet = true true @@ -113,7 +117,14 @@ @progress = %w[- \\ | /] @progress_bs = "\b" * @progress[0].size @tty = !@verbose && $stderr.tty? - if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"] + case @color + when nil + @color = @tty && /dumb/ !~ ENV["TERM"] + @color &= /mswin|mingw/ !~ RUBY_PLATFORM + when true + @tty = true + end + if @color @passed = "\e[#{ENV['PASSED_COLOR']||'32'}m" @failed = "\e[#{ENV['FAILED_COLOR']||'31'}m" @reset = "\e[m" Index: sample/test.rb =================================================================== --- sample/test.rb (revision 35839) +++ sample/test.rb (revision 35840) @@ -6,11 +6,23 @@ $failed = 0 PROGRESS = Object.new PROGRESS.instance_eval do + @color = nil + case ARGV[0] + when /\A--color(?:=(?:always|(auto)|(never)))?\z/ + @color = (!$2 unless $1) + end @count = 0 @rotator = %w[- \\ | /] @bs = "\b" * @rotator[0].size - @tty = STDERR.tty? - if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"] + @tty = STDERR.tty? && /dumb/ !~ ENV["TERM"] + @tty &&= /mswin|mingw/ !~ RUBY_PLATFORM + case @color + when nil + @color = @tty + when true + @tty = true + end + if @color @passed = "\e[#{ENV['PASSED_COLOR']||'32'}m" @failed = "\e[#{ENV['FAILED_COLOR']||'31'}m" @reset = "\e[m" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/