Re: [PATCH] Color support added to git-add--interactive.
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Oct 13, 2007, 12:25 UTC
- Message-ID
- <Pine.LNX.4.64.0710131321520.25221@racer.site>
- In-Reply-To
- <471045DA.5050902@gmail.com>
Hi,
[Cc'ed Wincent correctly]
On Fri, 12 Oct 2007, Dan Zwell wrote:
Show 14 quoted lines
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index be68814..f55d787 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -2,6 +2,18 @@
>
> use strict;
>
> +my $use_color;
> +my $color_config = qx(git config --get color.add-interactive);
> +if ($color_config=~"true" || -t STDOUT && $color_config=~"auto") {
> + $use_color = "true";
> + require Term::ANSIColor;
> +}Good. If you do not have color enabled, it does not require that package that is only default with modern Perl.
Show 7 quoted lines
> @@ -175,7 +187,9 @@ sub list_and_choose {
> if (!$opts->{LIST_FLAT}) {
> print " ";
> }
> + print_ansi_color "bold";
> print "$opts->{HEADER}\n";
> + print_ansi_color "clear";Here you say "clear", and ...
Show 10 quoted lines
> }
> for ($i = 0; $i < @stuff; $i++) {
> my $chosen = $chosen[$i] ? '*' : ' ';
> @@ -205,7 +219,9 @@ sub list_and_choose {
>
> return if ($opts->{LIST_ONLY});
>
> + print_ansi_color "bold blue";
> print $opts->{PROMPT};
> + print_ansi_color "reset";here you say "reset". Is it because of the added colour?
Show 16 quoted lines
> @@ -338,6 +354,16 @@ sub add_untracked_cmd {
>
> sub parse_diff {
> my ($path) = @_;
> + # FIXME: the following breaks git, and I'm not sure why. When
> + # the following is uncommented, git no longer asks whether we
> + # want to add given hunks.
> + #my @diff;
> + #if ($use_color) {
> + # #@diff = run_cmd_pipe(qw(git diff-files --color -p --), $path);
> + #}
> + #else {
> + # #@diff = run_cmd_pipe(qw(git diff-files -p --), $path);
> + #}
> my @diff = run_cmd_pipe(qw(git diff-files -p --), $path);
> my (@hunk) = { TEXT => [] };This fails because of the next two lines:
for (@diff) {
if (/^@@ /) {Replace the if with "if (/^[^-+ ]*@@ /)", or something even stricter. --color adds magic sequences to make color.
I cannot comment on the Perl style ;-)
Ciao, Dscho