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

add--interactive: allow diff colors without interactive colors

Users with color.diff set to true/auto will not see color in "git add -i" unless they also set color.interactive. This changes the semantics of color.interactive to control only the coloring of the interaction aspect of the command and let color.diff to control the color of hunk picker, which would arguably be more convenient. Old $use_color variable is now renamed to $menu_use_color to make it clear that it is about coloring the interaction. The "colored" subroutine now checks if the passed color is defined, instead of checking $use_color variable, to decide if the lines should be colored. The various variables that define colors for different parts of the output are set or unset depending on the setting of color.interactive and color.diff configuration variables. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 4, 2008 at 03:35 UTC f87e310d2c53f412cf9ba0a04e06c974c17b9062
1 file changed +15 -24
git-add--interactive.perl
+15 -24
@@ -3,38 +3,29 @@
3 use strict;
4 use Git;
5
6 -# Prompt colors:
7 -my ($prompt_color, $header_color, $help_color, $normal_color);
8 -# Diff colors:
9 -my ($fraginfo_color);
10 -
11 -my ($use_color, $diff_use_color);
6 my $repo = Git->repository();
7
14 -$use_color = $repo->get_colorbool('color.interactive');
15 -
16 -if ($use_color) {
17 - # Set interactive colors:
8 +my $menu_use_color = $repo->get_colorbool('color.interactive');
9 +my ($prompt_color, $header_color, $help_color) =
10 + $menu_use_color ? (
11 + $repo->get_color('color.interactive.prompt', 'bold blue'),
12 + $repo->get_color('color.interactive.header', 'bold'),
13 + $repo->get_color('color.interactive.help', 'red bold'),
14 + ) : ();
15
19 - # Grab the 3 main colors in git color string format, with sane
20 - # (visible) defaults:
21 - $prompt_color = $repo->get_color("color.interactive.prompt", "bold blue");
22 - $header_color = $repo->get_color("color.interactive.header", "bold");
23 - $help_color = $repo->get_color("color.interactive.help", "red bold");
24 - $normal_color = $repo->get_color("", "reset");
16 +my $diff_use_color = $repo->get_colorbool('color.diff');
17 +my ($fraginfo_color) =
18 + $diff_use_color ? (
19 + $repo->get_color('color.diff.frag', 'cyan'),
20 + ) : ();
21
26 - # Do we also set diff colors?
27 - $diff_use_color = $repo->get_colorbool('color.diff');
28 - if ($diff_use_color) {
29 - $fraginfo_color = $repo->get_color("color.diff.frag", "cyan");
30 - }
31 -}
22 +my $normal_color = $repo->get_color("", "reset");
23
24 sub colored {
25 my $color = shift;
26 my $string = join("", @_);
27
37 - if ($use_color) {
28 + if (defined $color) {
29 # Put a color code at the beginning of each line, a reset at the end
30 # color after newlines that are not at the end of the string
31 $string =~ s/(\n+)(.)/$1$color$2/g;
@@ -300,7 +291,7 @@ sub highlight_prefix {
291 return "$prefix$remainder";
292 }
293
303 - if (!$use_color) {
294 + if (!$menu_use_color) {
295 return "[$prefix]$remainder";
296 }
297