git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Dan Zwell <dzwell@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Wincent Colaiuta <win@wincent.com>,
	Git Mailing List <git@vger.kernel.org>,
	Jonathan del Strother <maillist@steelskies.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Frank Lichtenheld <frank@lichtenheld.de>
Subject: Re: revised: [PATCH] Color support added to git-add--interactive.
Date: Tue, 16 Oct 2007 19:47:09 -0500	[thread overview]
Message-ID: <20071016194709.3c1cb3a8@danzwell.com> (raw)
In-Reply-To: <20071015034338.GA4844@coredump.intra.peff.net>

[-- Attachment #1: Type: text/plain, Size: 4889 bytes --]

Adds color to the prompts and output of git-add--interactive.

-Reads config color.interactive, respects "auto", "true",
"always", and anything else.
-Uses the library Term::ANSIColor, which is included with modern
 versions of perl. This is optional, and should not need to be
 present if color.interactive is not on.
-Reads color.interactive.<slot>, where slot is "header", "prompt",
 or "help", colorizing output accordingly.

Documentation/config.txt is updated to reflect the new keys.
I cannot test this or see how it looks in manpages, however,
as I cannot install the documentation build tools.

Unfortunately, I think the default colors are ugly, but all colors that
are readable on both black and white backgrounds are probably ugly.

This patch does not colorize the diffs, because that is a larger
job, and very distinct from this (simple) task.

Dan

gzipped patch is also attached, just in case.

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 971fd9f..17e29e4 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -381,6 +381,27 @@ color.diff.<slot>::
 	whitespace).  The values of these variables may be specified as
 	in color.branch.<slot>.

+color.interactive::
+	When true (or `always`), always use colors in add--interactive.
+	When false (or `never`), never.  When set to `auto`, use
+	colors only when the output is to the terminal. Defaults to
+        false.
+
+color.interactive.<slot>::
+        Use customized color for add--interactive output. `<slot>`
+        may be `prompt`, `header`, or `help`, for three distinct types
+        of common output from interactive programs. The values may be a
+        space-delimited combination of up to three of the following:
++
+(optional attribute, optional foreground color, and optional
background) ++
+dark, bold, underline, underscore, blink, reverse, concealed,
+black, red, green, yellow, blue, magenta, cyan, white, on_black,
+on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white
++
+Note: these are not the same colors/attributes that the
+rest of git supports, but are specific to git-add--interactive.
+
 color.pager::
 	A boolean to enable/disable colored output when the pager is in
 	use (default is true).
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index be68814..125655b 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -2,6 +2,33 @@

 use strict;

+my ($use_color, $prompt_color, $header_color, $help_color);
+my $color_config = qx(git config --get color.interactive);
+if ($color_config=~/true|always/ || -t STDOUT &&
$color_config=~/auto/) {
+	$use_color = "true";
+	chomp( $prompt_color = qx(git config --get
color.interactive.prompt) );
+	chomp( $header_color = qx(git config --get
color.interactive.header) );
+	chomp( $help_color = qx(git config --get
color.interactive.help) );
+	$prompt_color ||= "red bold";
+	$header_color ||= "bold";
+	$help_color ||= "blue bold";
+
+	require Term::ANSIColor;
+}
+
+sub print_colored {
+	my $color = shift;
+	my @strings = @_;
+
+	if ($use_color) {
+		print Term::ANSIColor::color($color);
+		print(@strings);
+		print Term::ANSIColor::color("reset");
+	} else {
+		print @strings;
+	}
+}
+
 sub run_cmd_pipe {
 	if ($^O eq 'MSWin32') {
 		my @invalid = grep {m/[":*]/} @_;
@@ -175,7 +202,7 @@ sub list_and_choose {
 			if (!$opts->{LIST_FLAT}) {
 				print "     ";
 			}
-			print "$opts->{HEADER}\n";
+			print_colored $header_color,
"$opts->{HEADER}\n"; }
 		for ($i = 0; $i < @stuff; $i++) {
 			my $chosen = $chosen[$i] ? '*' : ' ';
@@ -205,7 +232,7 @@ sub list_and_choose {

 		return if ($opts->{LIST_ONLY});

-		print $opts->{PROMPT};
+		print_colored $prompt_color, $opts->{PROMPT};
 		if ($opts->{SINGLETON}) {
 			print "> ";
 		}
@@ -544,7 +571,7 @@ sub coalesce_overlapping_hunks {
 }

 sub help_patch_cmd {
-	print <<\EOF ;
+	print_colored $help_color, <<\EOF ;
 y - stage this hunk
 n - do not stage this hunk
 a - stage this and all the remaining hunks
@@ -619,7 +646,7 @@ sub patch_update_cmd {
 		for (@{$hunk[$ix]{TEXT}}) {
 			print;
 		}
-		print "Stage this hunk [y/n/a/d$other/?]? ";
+		print_colored $prompt_color, "Stage this hunk
[y/n/a/d$other/?]? "; my $line = <STDIN>;
 		if ($line) {
 			if ($line =~ /^y/i) {
@@ -673,7 +700,7 @@ sub patch_update_cmd {
 			elsif ($other =~ /s/ && $line =~ /^s/) {
 				my @split =
split_hunk($hunk[$ix]{TEXT}); if (1 < @split) {
-					print "Split into ",
+					print_colored "$header_color",
"Split into ", scalar(@split), " hunks.\n";
 				}
 				splice(@hunk, $ix, 1,
@@ -769,7 +796,7 @@ sub quit_cmd {
 }

 sub help_cmd {
-	print <<\EOF ;
+	print_colored $help_color, <<\EOF ;
 status        - show paths with changes
 update        - add working tree state to the staged set of changes
 revert        - revert staged set of changes back to the HEAD version
--
1.5.3.4.207.gc0ee


[-- Attachment #2: color-add--interactive.patch.gz --]
[-- Type: application/x-gzip, Size: 1749 bytes --]

  reply	other threads:[~2007-10-17  0:49 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
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           ` Dan Zwell [this message]
2007-10-17  1:51             ` revised: " 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=20071016194709.3c1cb3a8@danzwell.com \
    --to=dzwell@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=frank@lichtenheld.de \
    --cc=git@vger.kernel.org \
    --cc=maillist@steelskies.com \
    --cc=peff@peff.net \
    --cc=win@wincent.com \
    /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).