From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Zwell Subject: Re: revised: [PATCH] Color support added to git-add--interactive. Date: Tue, 16 Oct 2007 19:47:09 -0500 Message-ID: <20071016194709.3c1cb3a8@danzwell.com> References: <471045DA.5050902@gmail.com> <19271E58-5C4F-41AF-8F9D-F114F36A34AC@wincent.com> <20071013172745.GA2624@coredump.intra.peff.net> <20071013175127.GA3183@coredump.intra.peff.net> <47112491.8070309@gmail.com> <20071015034338.GA4844@coredump.intra.peff.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/TeEbOPut6I.5.LC2hA5.U9z" Cc: Wincent Colaiuta , Git Mailing List , Jonathan del Strother , Johannes Schindelin , Frank Lichtenheld To: Jeff King X-From: git-owner@vger.kernel.org Wed Oct 17 02:49:14 2007 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ihx5z-0002O1-AM for gcvg-git-2@gmane.org; Wed, 17 Oct 2007 02:49:12 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762308AbXJQAsh (ORCPT ); Tue, 16 Oct 2007 20:48:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1761797AbXJQAsh (ORCPT ); Tue, 16 Oct 2007 20:48:37 -0400 Received: from py-out-1112.google.com ([64.233.166.176]:9801 "EHLO py-out-1112.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751250AbXJQAsf (ORCPT ); Tue, 16 Oct 2007 20:48:35 -0400 Received: by py-out-1112.google.com with SMTP id u77so4015271pyb for ; Tue, 16 Oct 2007 17:48:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; bh=lwilha8PcG3ufd7yYzozJTkemh3LxGK9peSVj9ODrgY=; b=rS/1MD4u4Qj1jWVnu/wygvRzaX7LpxGEsjgZjp+C1s4QPsx2mcbOK8eqeV5UIco5voEhmKJRNMaPwBRczqqxOCh8pgwWUT8aCf/jJOUcIc9qFl/rQtSwUqkkLN69pp+VWlMWdd3DkRrNB0fEdnrH/xxIGDfqTwbkw9JpXHyO0JU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; b=SDpbKx7qisJjHXKed/XQ7MlKiYjKlzac9x8Yy1aRBweTkl0c90acUejX9OvSJq8M9JRDYexsy0WkeQooyJ9/5M7QTCuDnflz3415Z9WQZKMo7r3Wr8I8MPyoSjoK9fyqojiRrXZ5KtfRTCG3gam6QisnIEGLvRtao+NW19rCSGY= Received: by 10.65.133.8 with SMTP id k8mr14432597qbn.1192582113150; Tue, 16 Oct 2007 17:48:33 -0700 (PDT) Received: from danzwell.com ( [143.44.70.185]) by mx.google.com with ESMTPS id 15sm2139557nzp.2007.10.16.17.48.28 (version=SSLv3 cipher=OTHER); Tue, 16 Oct 2007 17:48:31 -0700 (PDT) In-Reply-To: <20071015034338.GA4844@coredump.intra.peff.net> X-Mailer: Claws Mail 3.0.2 (GTK+ 2.10.14; x86_64-pc-linux-gnu) Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org Archived-At: --MP_/TeEbOPut6I.5.LC2hA5.U9z Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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., 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.:: whitespace). The values of these variables may be specified as in color.branch.. +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.:: + Use customized color for add--interactive output. `` + 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 = ; 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 --MP_/TeEbOPut6I.5.LC2hA5.U9z Content-Type: application/x-gzip; name=color-add--interactive.patch.gz Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=color-add--interactive.patch.gz H4sICP5WFUcAA2NvbG9yLWFkZC0taW50ZXJhY3RpdmUucGF0Y2gApVdtb9tGEv5s/oo5QailSqJe bFnxSxMHF/cuQGoXtYreIU3lFbkSF6FIhruMrbPV337P7JKSrNhpDhfA4XJn5pn3GSpUsxl1OnNl SHTfpEGxkIkRRqVJN0iTmZr75s7Q9FmSp5JQ3tHxqD8Lj2e+3x/JwbE8pH6vd3R46HU6na/geq1W 62vY5+fUOXjRbx9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