From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tor Arvid Lund Subject: Re: [PATCH] git-gui: apply color information from git diff output Date: Fri, 22 Oct 2010 16:40:38 +0200 Message-ID: References: <87hbgh7paf.fsf@fox.patthoyts.tk> <87pqv4fqqz.fsf_-_@fox.patthoyts.tk> <7vy69stop2.fsf@alter.siamese.dyndns.org> <87eibje5zs.fsf_-_@fox.patthoyts.tk> <87pqv2ttjx.fsf_-_@fox.patthoyts.tk> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Kevin Ballard , Junio C Hamano , Git mailing list To: Pat Thoyts X-From: git-owner@vger.kernel.org Fri Oct 22 16:40:48 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P9InW-0002nR-HJ for gcvg-git-2@lo.gmane.org; Fri, 22 Oct 2010 16:40:47 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757361Ab0JVOkk convert rfc822-to-quoted-printable (ORCPT ); Fri, 22 Oct 2010 10:40:40 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:46622 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755015Ab0JVOkj convert rfc822-to-8bit (ORCPT ); Fri, 22 Oct 2010 10:40:39 -0400 Received: by ewy7 with SMTP id 7so1172605ewy.19 for ; Fri, 22 Oct 2010 07:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=zTuo3ckMA4aIKundPGEg9cjfz3wxFS6NL5mz+WYdXQw=; b=Uc0RR9K+DPJZ2uvYPmRI/qBRjRMN3sBXonHMK2napk2y0kduYhQYadqyp0u4AA1F8N EdqYmkF74IxGDWwikqVyGPrvr4q3/BllzSqY2+kn/SeOB/ZbhAC2nCKbE+z9pmPyx51N B4WaBw0DtYLiuF5SMOhNlCoXr8xlMh+RaOYsY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=bdCHzM/F6z58CYojZEfCix2Po5Rx51j2PuPuVmVF9bC+ax+HX+/eB6XPcD1BtOq5PW cOBlZ/AtGjDkwmyLd6Bi1OvXNuFk5e2est9IaNkLe1vPS8adusCfUP2X/Pp+scAMuhyP bL/YlsKa3/T4zk1mswkr3gHtFVNoMW+haQvS8= Received: by 10.14.126.69 with SMTP id a45mr2233997eei.15.1287758438134; Fri, 22 Oct 2010 07:40:38 -0700 (PDT) Received: by 10.220.76.74 with HTTP; Fri, 22 Oct 2010 07:40:38 -0700 (PDT) In-Reply-To: <87pqv2ttjx.fsf_-_@fox.patthoyts.tk> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: On Fri, Oct 22, 2010 at 12:10 PM, Pat Thoyts wrote: > This patch extracts the ANSI color sequences from git diff output and > applies these to the diff view window. This ensures that the gui view > makes use of the current git configuration for whitespace display. > > ANSI codes may include attributes, foreground and background in a sin= gle > sequence. Handle this and support bold and reverse attributes. Ignore > all other attributes. > > Suggested-by: Tor Arvid Lund > Suggested-by: Junio C Hamano > Signed-off-by: Pat Thoyts > --- Tested-by: Tor Arvid Lund It seems to work well for me. I'm just using the default (unset) core.whitespace settings, so space-before-tab and blank-at-eol both show up with red background, just like in the console. -Tor Arvid- > Kevin Ballard writes: > >>On Oct 21, 2010, at 8:22 AM, Pat Thoyts wrote: >> >>> + =C2=A0 =C2=A0while {[regexp -indices -start $start "\033\\\[(\\d+= )?m" $line match code]} { >> >>Git currently doesn't emit combined escapes (e.g. \e[0;31m to reset a= nd then turn on red text), but I can imagine it being enhanced to do th= is in the future. I would recommend handling it here if you can. >> >>-Kevin Ballard > > It turns out that such sequences will be generated by git if the user > configures the color.diff.whitespace (eg: bold cyan magenta). This pa= tch > handles these cases. I don't see any point trying to handle blink. I > could add underline but I don't see that being so appropriate for a > GUI. It seems more like something that is configured for a monochrome > terminal. > > =C2=A0git-gui.sh =C2=A0 | =C2=A0 10 +++++++++- > =C2=A0lib/diff.tcl | =C2=A0 34 +++++++++++++++++++++++++++++++++- > =C2=A02 files changed, 42 insertions(+), 2 deletions(-) > > diff --git a/git-gui.sh b/git-gui.sh > index 1ccaba1..1fb0254 100755 > --- a/git-gui.sh > +++ b/git-gui.sh > @@ -3322,8 +3322,16 @@ pack $ui_diff -side left -fill both -expand 1 > =C2=A0pack .vpane.lower.diff.header -side top -fill x > =C2=A0pack .vpane.lower.diff.body -side bottom -fill both -expand 1 > > +foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 = 6 cyan4 7 grey60} { > + =C2=A0 =C2=A0 =C2=A0 $ui_diff tag configure clr4$n -background $c > + =C2=A0 =C2=A0 =C2=A0 $ui_diff tag configure clri4$n -foreground $c > + =C2=A0 =C2=A0 =C2=A0 $ui_diff tag configure clr3$n -foreground $c > + =C2=A0 =C2=A0 =C2=A0 $ui_diff tag configure clri3$n -background $c > +} > +$ui_diff tag configure clr1 -font font_diffbold > + > =C2=A0$ui_diff tag conf d_cr -elide true > -$ui_diff tag conf d_@ -foreground blue -font font_diffbold > +$ui_diff tag conf d_@ -font font_diffbold > =C2=A0$ui_diff tag conf d_+ -foreground {#00a000} > =C2=A0$ui_diff tag conf d_- -foreground red > > diff --git a/lib/diff.tcl b/lib/diff.tcl > index c628750..dcf0711 100644 > --- a/lib/diff.tcl > +++ b/lib/diff.tcl > @@ -294,7 +294,7 @@ proc start_show_diff {cont_info {add_opts {}}} { > =C2=A0 =C2=A0 =C2=A0 =C2=A0} > > =C2=A0 =C2=A0 =C2=A0 =C2=A0lappend cmd -p > - =C2=A0 =C2=A0 =C2=A0 lappend cmd --no-color > + =C2=A0 =C2=A0 =C2=A0 lappend cmd --color > =C2=A0 =C2=A0 =C2=A0 =C2=A0if {$repo_config(gui.diffcontext) >=3D 1} = { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0lappend cmd "-= U$repo_config(gui.diffcontext)" > =C2=A0 =C2=A0 =C2=A0 =C2=A0} > @@ -332,6 +332,23 @@ proc start_show_diff {cont_info {add_opts {}}} { > =C2=A0 =C2=A0 =C2=A0 =C2=A0fileevent $fd readable [list read_diff $fd= $cont_info] > =C2=A0} > > +proc parse_color_line {line} { > + =C2=A0 =C2=A0 =C2=A0 set start 0 > + =C2=A0 =C2=A0 =C2=A0 set result "" > + =C2=A0 =C2=A0 =C2=A0 set markup [list] > + =C2=A0 =C2=A0 =C2=A0 set regexp {\033\[((?:\d+;)*\d+)?m} > + =C2=A0 =C2=A0 =C2=A0 while {[regexp -indices -start $start $regexp = $line match code]} { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 foreach {begin end= } $match break > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 append result [str= ing range $line $start [expr {$begin - 1}]] > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 lappend markup [st= ring length $result] \ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 [eval [linsert $code 0 string range $line]] > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 set start [incr en= d] > + =C2=A0 =C2=A0 =C2=A0 } > + =C2=A0 =C2=A0 =C2=A0 append result [string range $line $start end] > + =C2=A0 =C2=A0 =C2=A0 if {[llength $markup] < 4} {set markup {}} > + =C2=A0 =C2=A0 =C2=A0 return [list $result $markup] > +} > + > =C2=A0proc read_diff {fd cont_info} { > =C2=A0 =C2=A0 =C2=A0 =C2=A0global ui_diff diff_active is_submodule_di= ff > =C2=A0 =C2=A0 =C2=A0 =C2=A0global is_3way_diff is_conflict_diff curre= nt_diff_header > @@ -340,6 +357,9 @@ proc read_diff {fd cont_info} { > > =C2=A0 =C2=A0 =C2=A0 =C2=A0$ui_diff conf -state normal > =C2=A0 =C2=A0 =C2=A0 =C2=A0while {[gets $fd line] >=3D 0} { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 foreach {line mark= up} [parse_color_line $line] break > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 set line [string m= ap {\033 ^} $line] > + > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# -- Cleanup u= ninteresting diff header lines. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if {$::current= _diff_inheader} { > @@ -434,11 +454,23 @@ proc read_diff {fd cont_info} { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 set mark [$ui_diff= index "end - 1 line linestart"] > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$ui_diff inser= t end $line $tags > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if {[string in= dex $line end] eq "\r"} { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0$ui_diff tag add d_cr {end - 2c} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$ui_diff inser= t end "\n" $tags > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 foreach {posbegin = colbegin posend colend} $markup { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 set prefix clr > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 foreach style [split $colbegin ";"] { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if {$style eq "7"} {append prefix i= ; continue} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if {$style < 30 || $style > 47} {co= ntinue} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 set a "$mark linestart + $posbegin = chars" > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 set b "$mark linestart + $posend ch= ars" > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 catch {$ui_diff tag add $prefix$sty= le $a $b} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 } > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0$ui_diff conf -state disabled > > -- > 1.7.3.1.msysgit.0 > > >