From d05b55873164be639a15cca352db4447f219753d Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Sun, 10 Feb 2013 23:31:24 -0500 Subject: [PATCH] Use different color for pretend output. --- modules/ksb/Debug.pm | 22 ++++++++++++++++------ modules/ksb/Util.pm | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/modules/ksb/Debug.pm b/modules/ksb/Debug.pm index 58589b7..7865371 100644 --- a/modules/ksb/Debug.pm +++ b/modules/ksb/Debug.pm @@ -29,7 +29,7 @@ my $debugLevel = INFO; my $ipc; # Set only if we should forward log messages over IPC. # Colors -my ($RED, $GREEN, $YELLOW, $NORMAL, $BOLD) = ("") x 5; +my ($RED, $GREEN, $YELLOW, $NORMAL, $BOLD, $DIM) = ("") x 6; # Subroutine definitions @@ -42,6 +42,7 @@ sub colorize $str =~ s/y\[/$YELLOW/g; $str =~ s/r\[/$RED/g; $str =~ s/b\[/$BOLD/g; + $str =~ s/d\[/$DIM/g; return $str; } @@ -66,14 +67,18 @@ sub setColorfulOutput my $useColor = shift; if ($useColor) { - $RED = "\e[31m"; - $GREEN = "\e[32m"; + $RED = "\e[31m"; + $GREEN = "\e[32m"; $YELLOW = "\e[33m"; $NORMAL = "\e[0m"; - $BOLD = "\e[1m"; + $BOLD = "\e[1m"; + $DIM = "\e[34m"; # Really blue since dim doesn't work on konsole + + # But konsole does support xterm-256color... + $DIM = "\e[38;5;8m" if $ENV{TERM} =~ /-256color$/; } else { - ($RED, $GREEN, $YELLOW, $NORMAL, $BOLD) = ("") x 5; + ($RED, $GREEN, $YELLOW, $NORMAL, $BOLD, $DIM) = ("") x 6; } } @@ -181,7 +186,12 @@ sub error(@) sub pretend(@) { - print_clr(@_) if pretending(); + if (pretending()) { + my @lines = @_; + s/(\w)/d[$1/ foreach @lines; # Add dim prefix + # Clear suffix is actually implicit + print_clr(@lines); + } } 1; diff --git a/modules/ksb/Util.pm b/modules/ksb/Util.pm index 4adbef7..3dba443 100644 --- a/modules/ksb/Util.pm +++ b/modules/ksb/Util.pm @@ -154,7 +154,7 @@ sub safe_system(@) return system (@_) >> 8; } - pretend ("\tWould have run g['", join("' '", @_), "'"); + pretend ("\tWould have run g['" . join("' '", @_) . "'"); return 0; # Return true } @@ -444,7 +444,7 @@ sub log_command if (pretending()) { - pretend ("\tWould have run g['", join ("' '", @command), "'"); + pretend ("\tWould have run g['" . join ("' '", @command) . "'"); POSIX::_exit(0); }