git-gui: fix ANSI-color parsing
git diff always outputs color reset commands, even when the color for the current part is disabled (ie. normal). But the current ANSI-color parsing code assumes that color start and reset commands appear in matching pairs. Relax this assumption. Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
This commit is contained in:
12
lib/diff.tcl
12
lib/diff.tcl
@ -337,12 +337,20 @@ proc parse_color_line {line} {
|
|||||||
set result ""
|
set result ""
|
||||||
set markup [list]
|
set markup [list]
|
||||||
set regexp {\033\[((?:\d+;)*\d+)?m}
|
set regexp {\033\[((?:\d+;)*\d+)?m}
|
||||||
|
set need_reset 0
|
||||||
while {[regexp -indices -start $start $regexp $line match code]} {
|
while {[regexp -indices -start $start $regexp $line match code]} {
|
||||||
foreach {begin end} $match break
|
foreach {begin end} $match break
|
||||||
append result [string range $line $start [expr {$begin - 1}]]
|
append result [string range $line $start [expr {$begin - 1}]]
|
||||||
lappend markup [string length $result] \
|
set pos [string length $result]
|
||||||
[eval [linsert $code 0 string range $line]]
|
set col [eval [linsert $code 0 string range $line]]
|
||||||
set start [incr end]
|
set start [incr end]
|
||||||
|
if {$col eq "0" || $col eq ""} {
|
||||||
|
if {!$need_reset} continue
|
||||||
|
set need_reset 0
|
||||||
|
} else {
|
||||||
|
set need_reset 1
|
||||||
|
}
|
||||||
|
lappend markup $pos $col
|
||||||
}
|
}
|
||||||
append result [string range $line $start end]
|
append result [string range $line $start end]
|
||||||
if {[llength $markup] < 4} {set markup {}}
|
if {[llength $markup] < 4} {set markup {}}
|
||||||
|
Reference in New Issue
Block a user