From: Wincent Colaiuta Date: Tue, 23 Oct 2007 06:28:28 GMT Subject: Re: [PATCH 1/2] Added basic color support to git add --interactive Message-ID: In-Reply-To: <20071023040315.GA28312@coredump.intra.peff.net> El 23/10/2007, a las 6:03, Jeff King escribió: > This does nothing for embedded newlines in the strings, which means > that > you can end up with ${COLOR}text\n${RESET}, which fouls up changed > backgrounds. See commit 50f575fc. Since the strings you are > printing are > small, I don't see any problem with making a copy, using a regex to > insert the color coding, and printing that (I think I even posted > example code in a previous thread on this subject). I did too, where you add a third, optional "trailer" parameter to the function where you pass the newline if there is one (following the style of the functions in color.c). Pasting it below. Having said that, I think this kind of function belongs in Git.pm, and the dependency on Term::ANSIColor should be replaced with dependency-free code that generates the colors itself; this should be easy because the number of possible colors is small, Git thus far only uses a subset of the possible ANSI colors, and the C code for doing it is already there in color.c and just needs to be translated into Perl. sub print_ansi_color { my $color = shift; my $string = shift; my $trailer = shift; if ($use_color) { print Term::ANSIColor::color($color), $string, Term::ANSIColor::color('clear'); } else { print $string; } if ($trailer) { print $trailer; } } Cheers, Wincent