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>
This commit is contained in:
Jeff King 2008-01-04 03:35:21 -05:00 коммит произвёл Junio C Hamano
Родитель 50e3d1eeff
Коммит f87e310d2c
1 изменённых файлов: 15 добавлений и 24 удалений

Просмотреть файл

@ -3,38 +3,29 @@
use strict; use strict;
use Git; use Git;
# Prompt colors:
my ($prompt_color, $header_color, $help_color, $normal_color);
# Diff colors:
my ($fraginfo_color);
my ($use_color, $diff_use_color);
my $repo = Git->repository(); my $repo = Git->repository();
$use_color = $repo->get_colorbool('color.interactive'); my $menu_use_color = $repo->get_colorbool('color.interactive');
my ($prompt_color, $header_color, $help_color) =
$menu_use_color ? (
$repo->get_color('color.interactive.prompt', 'bold blue'),
$repo->get_color('color.interactive.header', 'bold'),
$repo->get_color('color.interactive.help', 'red bold'),
) : ();
if ($use_color) { my $diff_use_color = $repo->get_colorbool('color.diff');
# Set interactive colors: my ($fraginfo_color) =
$diff_use_color ? (
$repo->get_color('color.diff.frag', 'cyan'),
) : ();
# Grab the 3 main colors in git color string format, with sane my $normal_color = $repo->get_color("", "reset");
# (visible) defaults:
$prompt_color = $repo->get_color("color.interactive.prompt", "bold blue");
$header_color = $repo->get_color("color.interactive.header", "bold");
$help_color = $repo->get_color("color.interactive.help", "red bold");
$normal_color = $repo->get_color("", "reset");
# Do we also set diff colors?
$diff_use_color = $repo->get_colorbool('color.diff');
if ($diff_use_color) {
$fraginfo_color = $repo->get_color("color.diff.frag", "cyan");
}
}
sub colored { sub colored {
my $color = shift; my $color = shift;
my $string = join("", @_); my $string = join("", @_);
if ($use_color) { if (defined $color) {
# Put a color code at the beginning of each line, a reset at the end # Put a color code at the beginning of each line, a reset at the end
# color after newlines that are not at the end of the string # color after newlines that are not at the end of the string
$string =~ s/(\n+)(.)/$1$color$2/g; $string =~ s/(\n+)(.)/$1$color$2/g;
@ -300,7 +291,7 @@ sub highlight_prefix {
return "$prefix$remainder"; return "$prefix$remainder";
} }
if (!$use_color) { if (!$menu_use_color) {
return "[$prefix]$remainder"; return "[$prefix]$remainder";
} }