On Fri, Nov 02, 2007 at 10:41:00PM -0500, Dan Zwell wrote: > +sub print_colored { > + my $color = shift; > + my $string = join("", @_); > + > + if ($use_color) { > + # Put a color code at the beginning of each line, a reset at the end > + # color after newlines that are not at the end of the string > + $string =~ s/(\n+)(.)/$1$color$2/g; > + # reset before newlines > + $string =~ s/(\n+)/$normal_color$1/g; > + # codes at beginning and end (if necessary): > + $string =~ s/^/$color/; > + $string =~ s/$/$normal_color/ unless $string =~ /\n$/; > + } > + print $string; > +} This would probably be a bit more readable by marking the regex as multline using /m. Something like: $string =~ s/^/$color/mg; $string =~ s/.$/$&$normal_color/mg; which covers both the "start/end of line" and "start/end" of string cases. Also, if there is to be pager support for showing diffs, perhaps print_colored needs to take a filehandle argument (or, even simpler, change "print_colored(...)" to "print color(...), so the caller can use print as usual). -Peff - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html