Re: [PATCH] git-gui: apply color information from git diff output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 22, 2010 at 12:10 PM, Pat Thoyts
<patthoyts@xxxxxxxxxxxxxxxxxxxxx> 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 single
> sequence. Handle this and support bold and reverse attributes. Ignore
> all other attributes.
>
> Suggested-by: Tor Arvid Lund <torarvid@xxxxxxxxx>
> Suggested-by: Junio C Hamano <gitster@xxxxxxxxx>
> Signed-off-by: Pat Thoyts <patthoyts@xxxxxxxxxxxxxxxxxxxxx>
> ---

Tested-by: Tor Arvid Lund <torarvid@xxxxxxxxx>

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 <kevin@xxxxxx> writes:
>
>>On Oct 21, 2010, at 8:22 AM, Pat Thoyts wrote:
>>
>>> + Â Âwhile {[regexp -indices -start $start "\033\\\[(\\d+)?m" $line match code]} {
>>
>>Git currently doesn't emit combined escapes (e.g. \e[0;31m to reset and then turn on red text), but I can imagine it being enhanced to do this 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 patch
> 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.
>
> Âgit-gui.sh  |  10 +++++++++-
> Âlib/diff.tcl | Â 34 +++++++++++++++++++++++++++++++++-
> Â2 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
> Âpack .vpane.lower.diff.header -side top -fill x
> Âpack .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} {
> + Â Â Â $ui_diff tag configure clr4$n -background $c
> + Â Â Â $ui_diff tag configure clri4$n -foreground $c
> + Â Â Â $ui_diff tag configure clr3$n -foreground $c
> + Â Â Â $ui_diff tag configure clri3$n -background $c
> +}
> +$ui_diff tag configure clr1 -font font_diffbold
> +
> Â$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
> Â$ui_diff tag conf d_+ -foreground {#00a000}
> Â$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 {}}} {
> Â Â Â Â}
>
> Â Â Â Âlappend cmd -p
> - Â Â Â lappend cmd --no-color
> + Â Â Â lappend cmd --color
> Â Â Â Âif {$repo_config(gui.diffcontext) >= 1} {
> Â Â Â Â Â Â Â Âlappend cmd "-U$repo_config(gui.diffcontext)"
> Â Â Â Â}
> @@ -332,6 +332,23 @@ proc start_show_diff {cont_info {add_opts {}}} {
> Â Â Â Âfileevent $fd readable [list read_diff $fd $cont_info]
> Â}
>
> +proc parse_color_line {line} {
> + Â Â Â set start 0
> + Â Â Â set result ""
> + Â Â Â set markup [list]
> + Â Â Â set regexp {\033\[((?:\d+;)*\d+)?m}
> + Â Â Â while {[regexp -indices -start $start $regexp $line match code]} {
> + Â Â Â Â Â Â Â foreach {begin end} $match break
> + Â Â Â Â Â Â Â append result [string range $line $start [expr {$begin - 1}]]
> + Â Â Â Â Â Â Â lappend markup [string length $result] \
> + Â Â Â Â Â Â Â Â Â Â Â [eval [linsert $code 0 string range $line]]
> + Â Â Â Â Â Â Â set start [incr end]
> + Â Â Â }
> + Â Â Â append result [string range $line $start end]
> + Â Â Â if {[llength $markup] < 4} {set markup {}}
> + Â Â Â return [list $result $markup]
> +}
> +
> Âproc read_diff {fd cont_info} {
> Â Â Â Âglobal ui_diff diff_active is_submodule_diff
> Â Â Â Âglobal is_3way_diff is_conflict_diff current_diff_header
> @@ -340,6 +357,9 @@ proc read_diff {fd cont_info} {
>
> Â Â Â Â$ui_diff conf -state normal
> Â Â Â Âwhile {[gets $fd line] >= 0} {
> + Â Â Â Â Â Â Â foreach {line markup} [parse_color_line $line] break
> + Â Â Â Â Â Â Â set line [string map {\033 ^} $line]
> +
> Â Â Â Â Â Â Â Â# -- Cleanup uninteresting diff header lines.
> Â Â Â Â Â Â Â Â#
> Â Â Â Â Â Â Â Âif {$::current_diff_inheader} {
> @@ -434,11 +454,23 @@ proc read_diff {fd cont_info} {
> Â Â Â Â Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Â}
> + Â Â Â Â Â Â Â set mark [$ui_diff index "end - 1 line linestart"]
> Â Â Â Â Â Â Â Â$ui_diff insert end $line $tags
> Â Â Â Â Â Â Â Âif {[string index $line end] eq "\r"} {
> Â Â Â Â Â Â Â Â Â Â Â Â$ui_diff tag add d_cr {end - 2c}
> Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Â$ui_diff insert end "\n" $tags
> +
> + Â Â Â Â Â Â Â foreach {posbegin colbegin posend colend} $markup {
> + Â Â Â Â Â Â Â Â Â Â Â set prefix clr
> + Â Â Â Â Â Â Â Â Â Â Â foreach style [split $colbegin ";"] {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if {$style eq "7"} {append prefix i; continue}
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if {$style < 30 || $style > 47} {continue}
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â set a "$mark linestart + $posbegin chars"
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â set b "$mark linestart + $posend chars"
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â catch {$ui_diff tag add $prefix$style $a $b}
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }
> Â Â Â Â}
> Â Â Â Â$ui_diff conf -state disabled
>
> --
> 1.7.3.1.msysgit.0
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]