@matheusbsbs / matheus-bagliano / commits / a301973641
Fork 0

add -p: print errors in separate color

Print interaction error messages in color.interactive.error, which defaults to the value of color.interactive.help. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Feb 5, 2009 at 09:28 UTC a301973641f426ab42e5bf9faa6e4da5bd658148
2 files changed +22 -12
Documentation/config.txt
+2 -2
@@ -556,8 +556,8 @@ color.interactive::
556
557 color.interactive.<slot>::
558 Use customized color for 'git-add --interactive'
559 - output. `<slot>` may be `prompt`, `header`, or `help`, for
560 - three distinct types of normal output from interactive
559 + output. `<slot>` may be `prompt`, `header`, `help` or `error`, for
560 + four distinct types of normal output from interactive
561 programs. The values of these variables may be specified as
562 in color.branch.<slot>.
563
git-add--interactive.perl
+20 -10
@@ -12,6 +12,12 @@ my ($prompt_color, $header_color, $help_color) =
12 $repo->get_color('color.interactive.header', 'bold'),
13 $repo->get_color('color.interactive.help', 'red bold'),
14 ) : ();
15 +my $error_color = ();
16 +if ($menu_use_color) {
17 + my $help_color_spec = $repo->config('color.interactive.help');
18 + $error_color = $repo->get_color('color.interactive.error',
19 + $help_color_spec);
20 +}
21
22 my $diff_use_color = $repo->get_colorbool('color.diff');
23 my ($fraginfo_color) =
@@ -333,6 +339,10 @@ sub highlight_prefix {
339 return "$prompt_color$prefix$normal_color$remainder";
340 }
341
342 +sub error_msg {
343 + print STDERR colored $error_color, @_;
344 +}
345 +
346 sub list_and_choose {
347 my ($opts, @stuff) = @_;
348 my (@chosen, @return);
@@ -428,12 +438,12 @@ sub list_and_choose {
438 else {
439 $bottom = $top = find_unique($choice, @stuff);
440 if (!defined $bottom) {
431 - print "Huh ($choice)?\n";
441 + error_msg "Huh ($choice)?\n";
442 next TOPLOOP;
443 }
444 }
445 if ($opts->{SINGLETON} && $bottom != $top) {
436 - print "Huh ($choice)?\n";
446 + error_msg "Huh ($choice)?\n";
447 next TOPLOOP;
448 }
449 for ($i = $bottom-1; $i <= $top-1; $i++) {
@@ -1029,11 +1039,11 @@ sub patch_update_file {
1039 chomp $response;
1040 }
1041 if ($response !~ /^\s*\d+\s*$/) {
1032 - print STDERR "Invalid number: '$response'\n";
1042 + error_msg "Invalid number: '$response'\n";
1043 } elsif (0 < $response && $response <= $num) {
1044 $ix = $response - 1;
1045 } else {
1036 - print STDERR "Sorry, only $num hunks available.\n";
1046 + error_msg "Sorry, only $num hunks available.\n";
1047 }
1048 next;
1049 }
@@ -1062,7 +1072,7 @@ sub patch_update_file {
1072 if ($@) {
1073 my ($err,$exp) = ($@, $1);
1074 $err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
1065 - print STDERR "Malformed search regexp $exp: $err\n";
1075 + error_msg "Malformed search regexp $exp: $err\n";
1076 next;
1077 }
1078 my $iy = $ix;
@@ -1072,7 +1082,7 @@ sub patch_update_file {
1082 $iy++;
1083 $iy = 0 if ($iy >= $num);
1084 if ($ix == $iy) {
1075 - print STDERR "No hunk matches the given pattern\n";
1085 + error_msg "No hunk matches the given pattern\n";
1086 last;
1087 }
1088 }
@@ -1084,7 +1094,7 @@ sub patch_update_file {
1094 $ix--;
1095 }
1096 else {
1087 - print STDERR "No previous hunk\n";
1097 + error_msg "No previous hunk\n";
1098 }
1099 next;
1100 }
@@ -1093,7 +1103,7 @@ sub patch_update_file {
1103 $ix++;
1104 }
1105 else {
1096 - print STDERR "No next hunk\n";
1106 + error_msg "No next hunk\n";
1107 }
1108 next;
1109 }
@@ -1106,13 +1116,13 @@ sub patch_update_file {
1116 }
1117 }
1118 else {
1109 - print STDERR "No previous hunk\n";
1119 + error_msg "No previous hunk\n";
1120 }
1121 next;
1122 }
1123 elsif ($line =~ /^j/) {
1124 if ($other !~ /j/) {
1115 - print STDERR "No next hunk\n";
1125 + error_msg "No next hunk\n";
1126 next;
1127 }
1128 }