From: Wincent Colaiuta <win@wincent.com>
To: Dan Zwell <dzwell@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>, Jeff King <peff@peff.net>,
Jonathan del Strother <maillist@steelskies.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Frank Lichtenheld <frank@lichtenheld.de>
Subject: Re: [PATCH] Color support added to git-add--interactive.
Date: Sat, 13 Oct 2007 16:45:41 +0200 [thread overview]
Message-ID: <19271E58-5C4F-41AF-8F9D-F114F36A34AC@wincent.com> (raw)
In-Reply-To: <471045DA.5050902@gmail.com>
El 13/10/2007, a las 6:13, Dan Zwell escribió:
> Dan Zwell<Color-add-interactive.patch.gz>
Based on a couple of the suggestions you've received I made a couple
of changes to your patch and given it a quick try-out. I'm no perl
hacker so there may be better ways.
- as per Jeff's suggestion, changed your print_ansi_color method,
modelling it after the print_color_ln and color_vprintf functions
defined in color.c; accepts a color, a string, and an optional
trailer (where if there is a newline you pass it as the trailer)
- as Johannes pointed out, "clear" and "reset" are not used
consistently even though the Term::ANSIColor documentation says that
they're the same, so settled on "clear"; although in any case, the
changes to the print_ansi_color function mean that it is now the only
site where clearing takes place
- changed the regex as suggested by Johannes, and a couple of others
that are used when splitting hunks
- used more explicit notation for regex as proposed by Frank
Took it for a basic spin here and seems to work. Didn't even think
about implementing user-settable colors.
Cheers,
Wincent
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index be68814..ae3d11e 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -2,6 +2,28 @@
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;
+}
+
+sub print_ansi_color($$;$) {
+ my $color = shift;
+ my $string = shift;
+ my $trailer = shift;
+ if ($use_color) {
+ printf '%s%s%s', Term::ANSIColor::color($color), $string,
+ Term::ANSIColor::color('clear');
+ } else {
+ print $string;
+ }
+ if ($trailer) {
+ print $trailer;
+ }
+}
+
sub run_cmd_pipe {
if ($^O eq 'MSWin32') {
my @invalid = grep {m/[":*]/} @_;
@@ -175,7 +197,7 @@ sub list_and_choose {
if (!$opts->{LIST_FLAT}) {
print " ";
}
- print "$opts->{HEADER}\n";
+ print_ansi_color "bold", "$opts->{HEADER}", "\n";
}
for ($i = 0; $i < @stuff; $i++) {
my $chosen = $chosen[$i] ? '*' : ' ';
@@ -205,7 +227,7 @@ sub list_and_choose {
return if ($opts->{LIST_ONLY});
- print $opts->{PROMPT};
+ print_ansi_color "bold blue", $opts->{PROMPT};
if ($opts->{SINGLETON}) {
print "> ";
}
@@ -338,11 +360,17 @@ sub add_untracked_cmd {
sub parse_diff {
my ($path) = @_;
- my @diff = run_cmd_pipe(qw(git diff-files -p --), $path);
+ 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 (@hunk) = { TEXT => [] };
for (@diff) {
- if (/^@@ /) {
+ if (/^[^-+ ]*@@ /) {
push @hunk, { TEXT => [] };
}
push @{$hunk[-1]{TEXT}}, $_;
@@ -360,7 +388,7 @@ sub hunk_splittable {
sub parse_hunk_header {
my ($line) = @_;
my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
- $line =~ /^@@ -(\d+)(?:,(\d+)) \+(\d+)(?:,(\d+)) @@/;
+ $line =~ /^[^-+ ]*@@ -(\d+)(?:,(\d+)) \+(\d+)(?:,(\d+)) @@/;
return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
}
@@ -426,7 +454,7 @@ sub split_hunk {
}
push @{$this->{TEXT}}, $line;
$this->{ADDDEL}++;
- if ($line =~ /^-/) {
+ if ($line =~ /^[^-+ ]*-/) {
$this->{OCNT}++;
}
else {
@@ -483,7 +511,7 @@ sub merge_hunk {
$o_cnt = $n_cnt = 0;
for ($i = 1; $i < @{$prev->{TEXT}}; $i++) {
my $line = $prev->{TEXT}[$i];
- if ($line =~ /^\+/) {
+ if ($line =~ /^[^-+ ]*\+/) {
$n_cnt++;
push @line, $line;
next;
@@ -501,7 +529,7 @@ sub merge_hunk {
for ($i = 1; $i < @{$this->{TEXT}}; $i++) {
my $line = $this->{TEXT}[$i];
- if ($line =~ /^\+/) {
+ if ($line =~ /^[^-+ ]*\+/) {
$n_cnt++;
push @line, $line;
next;
@@ -544,7 +572,7 @@ sub coalesce_overlapping_hunks {
}
sub help_patch_cmd {
- print <<\EOF ;
+ my $help = <<\EOF ;
y - stage this hunk
n - do not stage this hunk
a - stage this and all the remaining hunks
@@ -555,6 +583,7 @@ k - leave this hunk undecided, see previous
undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
EOF
+ print_ansi_color "blue", $_, "\n" foreach (split /[\r\n]/, $help);
}
sub patch_update_cmd {
@@ -619,7 +648,7 @@ sub patch_update_cmd {
for (@{$hunk[$ix]{TEXT}}) {
print;
}
- print "Stage this hunk [y/n/a/d$other/?]? ";
+ print_ansi_color "bold", "Stage this hunk [y/n/a/d$other/?]? ";
my $line = <STDIN>;
if ($line) {
if ($line =~ /^y/i) {
next prev parent reply other threads:[~2007-10-13 14:47 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-13 4:13 [PATCH] Color support added to git-add--interactive Dan Zwell
2007-10-13 8:12 ` Jeff King
2007-10-13 12:49 ` Frank Lichtenheld
2007-10-13 12:25 ` Johannes Schindelin
2007-10-13 14:45 ` Wincent Colaiuta [this message]
2007-10-13 16:38 ` Jean-Luc Herren
2007-10-13 17:14 ` Wincent Colaiuta
2007-10-13 18:31 ` Andreas Ericsson
2007-10-13 16:38 ` Johannes Schindelin
2007-10-13 17:27 ` Jeff King
2007-10-13 17:51 ` Jeff King
2007-10-13 20:03 ` Dan Zwell
2007-10-13 20:36 ` Wincent Colaiuta
2007-10-13 21:50 ` Dan Z
2007-10-13 22:23 ` Jean-Luc Herren
2007-10-15 3:43 ` Jeff King
2007-10-17 0:47 ` revised: " Dan Zwell
2007-10-17 1:51 ` Shawn O. Pearce
2007-10-17 7:57 ` Dan Zwell
2007-10-17 8:11 ` Shawn O. Pearce
2007-10-22 21:32 ` [PATCH 1/2] Added basic color support to git add --interactive Dan Zwell
2007-10-23 2:11 ` [PATCH] resend of git-add--interactive color patch against spearce/pu Dan Zwell
2007-10-23 2:19 ` [PATCH] Let git-add--interactive read "git colors" from git-config Dan Zwell
2007-10-23 4:29 ` Jeff King
2007-10-23 4:40 ` Shawn O. Pearce
2007-10-23 4:03 ` [PATCH 1/2] Added basic color support to git add --interactive Jeff King
2007-10-23 6:28 ` Wincent Colaiuta
2007-10-23 6:41 ` Jeff King
2007-10-23 7:44 ` Wincent Colaiuta
2007-10-22 21:40 ` [PATCH 2/2] Let git-add--interactive read colors from git-config Dan Zwell
2007-10-23 4:27 ` Jeff King
2007-10-23 8:52 ` Dan Zwell
2007-11-03 3:41 ` [PATCH 1/2] Added basic color support to git add --interactive Dan Zwell
2007-11-04 4:57 ` Jeff King
2007-11-04 5:36 ` Junio C Hamano
2007-11-04 5:43 ` Jeff King
2007-11-11 0:01 ` [PATCH 0/3] Adding colors to git-add--interactive Dan Zwell
2007-11-11 7:54 ` Jeff King
2007-11-11 8:23 ` Junio C Hamano
2007-11-11 8:39 ` Dan Zwell
2007-11-22 10:54 ` [PATCH 0/5] Colors for git-add--interactive Dan Zwell
2007-11-22 11:57 ` Jeff King
2007-11-22 19:20 ` Junio C Hamano
2007-11-22 10:54 ` [PATCH 1/5] Added basic color support to git add --interactive Dan Zwell
2007-11-22 10:55 ` [PATCH 2/5] Don't return 'undef' in case called in a vector context Dan Zwell
2007-11-22 12:06 ` Jeff King
2007-11-22 21:17 ` Junio C Hamano
2007-11-23 4:15 ` Dan Zwell
2007-11-22 10:55 ` [PATCH 3/5] Added config_default($key, $default) to Git.pm Dan Zwell
2007-11-22 12:14 ` Jeff King
2007-11-22 10:56 ` [PATCH 4/5] Let git-add--interactive read colors from configuration Dan Zwell
2007-11-22 12:18 ` Jeff King
2007-11-22 21:28 ` Junio C Hamano
2007-11-22 22:30 ` Jeff King
2007-11-23 5:32 ` Dan Zwell
2007-11-23 9:09 ` Jeff King
2007-11-23 9:17 ` Junio C Hamano
2007-11-22 10:56 ` [PATCH 5/5] Added diff hunk coloring to git-add--interactive Dan Zwell
2007-11-22 12:25 ` Jeff King
2007-11-22 21:37 ` Junio C Hamano
2007-11-23 10:21 ` Jeff King
2007-11-22 22:35 ` Junio C Hamano
2007-11-11 0:01 ` [PATCH 1/3] Added basic color support to git add --interactive Dan Zwell
2007-11-11 0:02 ` [PATCH 2/3] Let git-add--interactive read colors from .gitconfig Dan Zwell
2007-11-11 0:03 ` [PATCH 3/3] Added diff hunk coloring to git-add--interactive Dan Zwell
2007-11-11 10:00 ` Junio C Hamano
2007-11-11 2:21 ` [PATCH 0/3] Adding colors " Dan Zwell
2007-11-11 2:23 ` Subject: [PATCH 1/3] Added basic color support to git add --interactive Dan Zwell
2007-11-11 19:56 ` Junio C Hamano
2007-11-11 2:23 ` Subject: [PATCH 2/3] Let git-add--interactive read colors from .gitconfig Dan Zwell
2007-11-11 9:53 ` Junio C Hamano
2007-11-11 10:34 ` Junio C Hamano
2007-11-13 1:39 ` Dan Zwell
2007-11-13 2:32 ` Junio C Hamano
2007-11-13 2:55 ` Dan Zwell
2007-11-13 7:26 ` Jeff King
2007-11-13 7:29 ` Junio C Hamano
2007-11-13 8:25 ` Dan Zwell
2007-11-13 9:46 ` Jakub Narebski
2007-11-03 3:41 ` [PATCH 2/2] " Dan Zwell
2007-11-03 5:06 ` *[PATCH " Junio C Hamano
2007-11-03 7:26 ` Dan Zwell
2007-11-03 18:11 ` Junio C Hamano
2007-10-15 4:12 ` [PATCH] Color support added to git-add--interactive Jeff King
2007-10-13 20:21 ` Tom Tobin
2007-10-13 20:26 ` Tom Tobin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19271E58-5C4F-41AF-8F9D-F114F36A34AC@wincent.com \
--to=win@wincent.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=dzwell@gmail.com \
--cc=frank@lichtenheld.de \
--cc=git@vger.kernel.org \
--cc=maillist@steelskies.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).