From be8a9db524121279a86cc085c275c7205795a081 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 22 Oct 2015 14:02:38 +0000 Subject: colorize * tool/generic_erb.rb: use VT100 sequence if tput does not work. * tool/ifchange: ditto and add --color option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/generic_erb.rb | 4 ++-- tool/ifchange | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'tool') diff --git a/tool/generic_erb.rb b/tool/generic_erb.rb index 149de3b1b9..ac1ef7db40 100644 --- a/tool/generic_erb.rb +++ b/tool/generic_erb.rb @@ -24,8 +24,8 @@ end 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}" diff --git a/tool/ifchange b/tool/ifchange index 7d7b377be7..4164572b76 100755 --- a/tool/ifchange +++ b/tool/ifchange @@ -5,6 +5,7 @@ set -e timestamp= keepsuffix= empty= +color=auto until [ $# -eq 0 ]; do case "$1" in --timestamp) @@ -22,6 +23,12 @@ until [ $# -eq 0 ]; do --empty) empty=yes ;; + --color) + color=always + ;; + --color=*) + color=`expr \( "$1" : '[^=]*=\(.*\)' \)` + ;; *) break ;; @@ -38,11 +45,10 @@ if [ "$temp" = - ]; then 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=\([^:]*\):"` -- cgit v1.2.3