git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] Color support for "git-add -i"

From
Jeff King <peff@peff.net>
Date
Dec 6, 2007, 05:40 UTC
Message-ID
<20071206054056.GG5499@coredump.intra.peff.net>
In-Reply-To
<1196906706-11170-3-git-send-email-gitster@pobox.com>
On Wed, Dec 05, 2007 at 06:05:05PM -0800, Junio C Hamano wrote:
> This is mostly lifted from earlier series by Dan Zwell, but updated to
> use "git config --get-color" and "git config --get-colorbool" to make it
> simpler and more consistent with commands written in C.

Looks mostly sane, except for the colorbool issues I mentioned in response to 2/3.

Show 13 quoted lines
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 335c2c6..1019a72 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> [...]
> +	# Do we also set diff colors?
> +	$diff_use_color = $repo->get_colorbool('color.diff');
> +	if ($diff_use_color) {
> +		$new_color = $repo->get_color("color.diff.new", "green");
> +		$old_color = $repo->get_color("color.diff.old", "red");
> +		$fraginfo_color = $repo->get_color("color.diff.frag", "cyan");
> +		$metainfo_color = $repo->get_color("color.diff.meta", "bold");
> +		$whitespace_color = $repo->get_color("color.diff.whitespace", "normal red");
diff.color support?

BTW, I am nagging about this because we never resolved what should happen. I am fine with the answer being "we are dropping support now."

Show 16 quoted lines
> +sub colored {
> +	my $color = shift;
> +	my $string = join("", @_);
> +
> +	if ($use_color) {
> +		# 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
> +		$string =~ s/(\n+)(.)/$1$color$2/g;
> +		# reset before newlines
> +		$string =~ s/(\n+)/$normal_color$1/g;
> +		# codes at beginning and end (if necessary):
> +		$string =~ s/^/$color/;
> +		$string =~ s/$/$normal_color/ unless $string =~ /\n$/;
> +	}
> +	return $string;
> +}

I still think this should go into Git.pm; I believe git-svn could make use of it.

Show 21 quoted lines
>  sub highlight_prefix {
>  	my $prefix = shift;
>  	my $remainder = shift;
> -	return $remainder unless defined $prefix;
> -	return is_valid_prefix($prefix) ?
> -	    "[$prefix]$remainder" :
> -	    "$prefix$remainder";
> +
> +	if (!defined $prefix) {
> +		return $remainder;
> +	}
> +
> +	if (!is_valid_prefix($prefix)) {
> +		return "$prefix$remainder";
> +	}
> +
> +	if (!$use_color) {
> +		return "[$prefix]$remainder";
> +	}
> +
> +	return "$prompt_color$prefix$normal_color$remainder";

Honestly, I find this blue+white coloring of the prefixes a bit ugly, but that is not your fault. :)

-Peff
Previous: Junio C HamanoNext: Wincent Colaiuta
Message 9 of 18 in “Color support for "git-add -i"”
  1. Color support for "git-add -i"Junio C Hamano, Dec 5, 2007
  2. Johannes SixtDec 5, 2007
  3. Wincent ColaiutaDec 5, 2007
  4. Junio C HamanoDec 5, 2007
  5. 1/3 Documentation: color.* = true means "auto"Junio C Hamano, Dec 6, 2007
  6. 2/3 git config --get-colorboolJunio C Hamano, Dec 6, 2007
  7. 3/3 Color support for "git-add -i"Junio C Hamano, Dec 6, 2007
  8. 0/3 Reroll colorized "git add -i"Junio C Hamano, Dec 6, 2007
  9. Jeff KingDec 6, 2007
  10. Wincent ColaiutaDec 6, 2007
  11. Junio C HamanoDec 6, 2007
  12. Wincent ColaiutaDec 7, 2007
  13. Jeff KingDec 6, 2007
  14. Jeff KingDec 6, 2007
  15. Junio C HamanoDec 6, 2007
  16. Jeff KingDec 6, 2007
  17. Eric WongDec 6, 2007
  18. Wincent ColaiutaDec 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.