ruby-changes:40139
From: nobu <ko1@a...>
Date: Thu, 22 Oct 2015 23:02:50 +0900 (JST)
Subject: [ruby-changes:40139] nobu:r52220 (trunk): colorize
nobu 2015-10-22 23:02:38 +0900 (Thu, 22 Oct 2015) New Revision: 52220 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52220 Log: colorize * tool/generic_erb.rb: use VT100 sequence if tput does not work. * tool/ifchange: ditto and add --color option. Modified files: trunk/tool/generic_erb.rb trunk/tool/ifchange Index: tool/generic_erb.rb =================================================================== --- tool/generic_erb.rb (revision 52219) +++ tool/generic_erb.rb (revision 52220) @@ -24,8 +24,8 @@ end https://github.com/ruby/ruby/blob/trunk/tool/generic_erb.rb#L24 unchanged = "unchanged" updated = "updated" if color or (color == nil && STDOUT.tty?) - if (/\A(\e\[).*m\z/ =~ IO.popen("tput smso", "r", err: IO::NULL, &:read) rescue nil) - beg = $1 + 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]*)/)] : {} reset = "#{beg}m" unchanged = "#{beg}#{colors["pass"] || "32;1"}m#{unchanged}#{reset}" Index: tool/ifchange =================================================================== --- tool/ifchange (revision 52219) +++ tool/ifchange (revision 52220) @@ -5,6 +5,7 @@ set -e https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L5 timestamp= keepsuffix= empty= +color=auto until [ $# -eq 0 ]; do case "$1" in --timestamp) @@ -22,6 +23,12 @@ until [ $# -eq 0 ]; do https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L23 --empty) empty=yes ;; + --color) + color=always + ;; + --color=*) + color=`expr \( "$1" : '[^=]*=\(.*\)' \)` + ;; *) break ;; @@ -38,11 +45,10 @@ if [ "$temp" = - ]; then https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L45 fi msg_begin= msg_unchanged= msg_updated= msg_reset= -if [ -t 1 ]; then - msg_begin="`tput smso 2>/dev/null`" || : - case "$msg_begin" in - ""*m) - msg_begin="`echo "$msg_begin" | sed 's/[0-9]*m$//'`" +if [ "$color" = always -o \( "$color" = auto -a -t 1 \) ]; then + msg_begin="[" + case "`tput smso 2>/dev/null`" in + "$msg_begin"*m|"") if [ ${TEST_COLORS:+set} ]; then msg_unchanged=`expr ":$TEST_COLORS:" : ".*:pass=\([^:]*\):"` msg_updated=`expr ":$TEST_COLORS:" : ".*:fail=\([^:]*\):"` -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/