From: Jeff King Date: Tue, 23 Oct 2007 04:03:16 GMT Subject: Re: [PATCH 1/2] Added basic color support to git add --interactive Message-ID: <20071023040315.GA28312@coredump.intra.peff.net> In-Reply-To: <20071022163244.4af72973@danzwell.com> On Mon, Oct 22, 2007 at 04:32:44PM -0500, Dan Zwell wrote: > +my ($use_color, $prompt_color, $header_color, $help_color); > +my $color_config = qx(git config --get color.interactive); > +if ($color_config=~/true|always/ || -t STDOUT && $color_config=~/auto/) { > + $use_color = "true"; > + # Sane (visible) defaults: > + $prompt_color = "blue bold"; > + $header_color = "bold"; > + $help_color = "red bold"; Bad indentation? > +sub print_colored { > + my $color = shift; > + my @strings = @_; > + > + if ($use_color) { > + print Term::ANSIColor::color($color); > + print(@strings); > + print Term::ANSIColor::color("reset"); > + } else { > + print @strings; > + } > +} 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). -Peff