[前][次][番号順一覧][スレッド一覧]

ruby-changes:56532

From: Hiroshi <ko1@a...>
Date: Mon, 15 Jul 2019 09:51:03 +0900 (JST)
Subject: [ruby-changes:56532] Hiroshi SHIBATA: e8ddbc0239 (master): Put colorize to library directory.

https://git.ruby-lang.org/ruby.git/commit/?id=e8ddbc0239

From e8ddbc0239b9dfa32787e93c6942f085e5c42b49 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Mon, 15 Jul 2019 08:54:34 +0900
Subject: Put colorize to library directory.

  Same as 66299e7ca83d379d13abaa5411f3e0419334cabb

diff --git a/tool/colorize.rb b/tool/colorize.rb
deleted file mode 100644
index 855e133..0000000
--- a/tool/colorize.rb
+++ /dev/null
@@ -1,50 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/#L0
-# frozen-string-literal: true
-
-class Colorize
-  def initialize(color = nil, opts = ((_, color = color, nil)[0] if Hash === color))
-    @colors = @reset = nil
-    if color or (color == nil && STDOUT.tty?)
-      if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", :err => IO::NULL, &:read) rescue nil)
-        @beg = "\e["
-        colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
-        if opts and colors_file = opts[:colors_file]
-          begin
-            File.read(colors_file).scan(/(\w+)=([^:\n]*)/) do |n, c|
-              colors[n] ||= c
-            end
-          rescue Errno::ENOENT
-          end
-        end
-        @colors = colors
-        @reset = "#{@beg}m"
-      end
-    end
-    self
-  end
-
-  DEFAULTS = {
-    "pass"=>"32", "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])
-      "#{@beg}#{color}m#{str}#{@reset}"
-    else
-      str
-    end
-  end
-
-  DEFAULTS.each_key do |name|
-    define_method(name) {|str|
-      decorate(str, name)
-    }
-  end
-end
-
-if $0 == __FILE__
-  colorize = Colorize.new
-  col = ARGV.shift
-  ARGV.each {|str| puts colorize.decorate(str, col)}
-end
diff --git a/tool/extlibs.rb b/tool/extlibs.rb
index efae167..f021a2b 100755
--- a/tool/extlibs.rb
+++ b/tool/extlibs.rb
@@ -5,7 +5,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/extlibs.rb#L5
 
 require 'digest'
 require_relative 'downloader'
-require_relative 'colorize'
+require_relative 'lib/colorize'
 
 class ExtLibs
   def initialize
diff --git a/tool/generic_erb.rb b/tool/generic_erb.rb
index 3904b57..3184cbb 100644
--- a/tool/generic_erb.rb
+++ b/tool/generic_erb.rb
@@ -7,7 +7,7 @@ require 'erb' https://github.com/ruby/ruby/blob/trunk/tool/generic_erb.rb#L7
 require 'optparse'
 $:.unshift(File.dirname(__FILE__))
 require 'vpath'
-require 'colorize'
+require_relative 'lib/colorize'
 
 vpath = VPath.new
 timestamp = nil
diff --git a/tool/leaked-globals b/tool/leaked-globals
index 48e8ec7..de17038 100755
--- a/tool/leaked-globals
+++ b/tool/leaked-globals
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/tool/leaked-globals#L1
 #!/usr/bin/ruby
-require_relative 'colorize'
+require_relative 'lib/colorize'
 
 until ARGV.empty?
   case ARGV[0]
diff --git a/tool/lib/colorize.rb b/tool/lib/colorize.rb
new file mode 100644
index 0000000..855e133
--- /dev/null
+++ b/tool/lib/colorize.rb
@@ -0,0 +1,50 @@ https://github.com/ruby/ruby/blob/trunk/tool/lib/colorize.rb#L1
+# frozen-string-literal: true
+
+class Colorize
+  def initialize(color = nil, opts = ((_, color = color, nil)[0] if Hash === color))
+    @colors = @reset = nil
+    if color or (color == nil && STDOUT.tty?)
+      if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", :err => IO::NULL, &:read) rescue nil)
+        @beg = "\e["
+        colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
+        if opts and colors_file = opts[:colors_file]
+          begin
+            File.read(colors_file).scan(/(\w+)=([^:\n]*)/) do |n, c|
+              colors[n] ||= c
+            end
+          rescue Errno::ENOENT
+          end
+        end
+        @colors = colors
+        @reset = "#{@beg}m"
+      end
+    end
+    self
+  end
+
+  DEFAULTS = {
+    "pass"=>"32", "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])
+      "#{@beg}#{color}m#{str}#{@reset}"
+    else
+      str
+    end
+  end
+
+  DEFAULTS.each_key do |name|
+    define_method(name) {|str|
+      decorate(str, name)
+    }
+  end
+end
+
+if $0 == __FILE__
+  colorize = Colorize.new
+  col = ARGV.shift
+  ARGV.each {|str| puts colorize.decorate(str, col)}
+end
diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb
index 5a98060..d237a9a 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -6,7 +6,7 @@ end https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L6
 require 'minitest/unit'
 require 'test/unit/assertions'
 require_relative '../envutil'
-require_relative '../../../tool/colorize'
+require_relative '../colorize'
 require 'test/unit/testcase'
 require 'optparse'
 
diff --git a/tool/make-snapshot b/tool/make-snapshot
index d6530b3..ad5fd87 100755
--- a/tool/make-snapshot
+++ b/tool/make-snapshot
@@ -8,7 +8,7 @@ require 'shellwords' https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L8
 require 'tmpdir'
 require 'pathname'
 require File.expand_path("../lib/vcs", __FILE__)
-require File.expand_path("../colorize", __FILE__)
+require File.expand_path("../lib/colorize", __FILE__)
 STDOUT.sync = true
 
 $srcdir ||= nil
diff --git a/tool/pure_parser.rb b/tool/pure_parser.rb
index 20d7107..4d5e86e 100755
--- a/tool/pure_parser.rb
+++ b/tool/pure_parser.rb
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/tool/pure_parser.rb#L1
 #!/usr/bin/ruby -pi
 BEGIN {
-  require_relative 'colorize'
+  require_relative 'lib/colorize'
 
   colorize = Colorize.new
   file = ARGV.shift
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]