ruby-changes:46972
From: nobu <ko1@a...>
Date: Thu, 15 Jun 2017 11:39:13 +0900 (JST)
Subject: [ruby-changes:46972] nobu:r59087 (trunk): make-snapshot: colorize [ci skip]
nobu 2017-06-15 11:39:06 +0900 (Thu, 15 Jun 2017) New Revision: 59087 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59087 Log: make-snapshot: colorize [ci skip] Modified files: trunk/tool/colorize.rb trunk/tool/make-snapshot Index: tool/make-snapshot =================================================================== --- tool/make-snapshot (revision 59086) +++ tool/make-snapshot (revision 59087) @@ -7,6 +7,7 @@ require 'fileutils' https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L7 require 'shellwords' require 'tmpdir' require File.expand_path("../vcs", __FILE__) +require File.expand_path("../colorize", __FILE__) STDOUT.sync = true $srcdir ||= nil @@ -18,6 +19,7 @@ $packages ||= nil https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L19 $digests ||= nil $tooldir = File.expand_path("..", __FILE__) $unicode_version = nil if ($unicode_version ||= nil) == "" +$colorize = Colorize.new def usage <<USAGE @@ -262,7 +264,17 @@ def package(vcs, rev, destdir, tmp = nil https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L264 end system(*%W"patch -d #{v} -p0 -i #{$patch_file}") if $patch_file if !$exported or $patch_file - "take a breath, and go ahead".scan(/./) {|c|print c; sleep(c == "," ? 0.7 : 0.05)}; puts + colors = %w[red yellow green cyan blue magenta] + "take a breath, and go ahead".scan(/./) do |c| + if c == ' ' + print c + else + colors.push(color = colors.shift) + print $colorize.decorate(c, color) + end + sleep(c == "," ? 0.7 : 0.05) + end + puts end def (clean = []).add(n) push(n); n end Dir.chdir(v) do @@ -277,10 +289,10 @@ def package(vcs, rev, destdir, tmp = nil https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L289 unless File.exist?("configure") print "creating configure..." unless system([ENV["AUTOCONF"]]*2) - puts " failed" + puts $colorize.fail(" failed") return end - puts " done" + puts $colorize.pass(" done") end clean.add("autom4te.cache") clean.add("enc/unicode/data") @@ -354,10 +366,10 @@ update-gems: https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L366 FileUtils.rm_rf("gems") end unless $?.success? - puts " failed" + puts $colorize.fail(" failed") return end - puts " done" + puts $colorize.pass(" done") end if v == "." @@ -381,9 +393,9 @@ update-gems: https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L393 tarball = "#{$archname||v}.tar" print "creating tarball... #{tarball}" if system("tar", "cf", tarball, v) - puts " done" + puts $colorize.pass(" done") else - puts " failed" + puts $colorize.fail(" failed") tarball = "" next end @@ -401,10 +413,10 @@ update-gems: https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L413 done = system(*cmd) end if done - puts " done" + puts $colorize.pass(" done") file else - puts " failed" + puts $colorize.fail(" failed") nil end end.compact @@ -432,7 +444,7 @@ revisions.collect {|rev| package(vcs, re https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L444 next end str = open(name, "rb") {|f| f.read} - puts "* #{name}" + puts "* #{$colorize.pass(name)}" puts " SIZE: #{str.bytesize} bytes" $digests.each do |alg| printf " %-8s%s\n", "#{alg}:", Digest.const_get(alg).hexdigest(str) Index: tool/colorize.rb =================================================================== --- tool/colorize.rb (revision 59086) +++ tool/colorize.rb (revision 59087) @@ -1,3 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/tool/colorize.rb#L1 +# frozen-string-literal: true + class Colorize def initialize(color = nil) @colors = @reset = nil @@ -11,7 +13,11 @@ class Colorize https://github.com/ruby/ruby/blob/trunk/tool/colorize.rb#L13 self end - DEFAULTS = {"pass"=>"32;1", "fail"=>"31;1", "skip"=>"33;1"} + DEFAULTS = { + "pass"=>"32;1", "fail"=>"31;1", "skip"=>"33;1", + "black"=>"30", "red"=>"31", "green"=>"32", "yellow"=>"33", + "blue"=>"34", "magenta"=>"35", "cyan"=>"36", "white"=>"37", + } def decorate(str, name) if @colors and color = (@colors[name] || DEFAULTS[name]) @@ -21,16 +27,10 @@ class Colorize https://github.com/ruby/ruby/blob/trunk/tool/colorize.rb#L27 end end - def pass(str) - decorate(str, "pass") - end - - def fail(str) - decorate(str, "fail") - end - - def skip(str) - decorate(str, "skip") + DEFAULTS.each_key do |name| + define_method(name) {|str| + decorate(str, name) + } end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/