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>
Bert Wesarg committed
Nov 15, 2010 at 11:00 UTC
46a0431b996cd19f21e0247c97b1eab2c19698fc
1 file changed
+10
-2
lib/diff.tcl
+10
-2
@@ -337,12 +337,20 @@ proc parse_color_line {line} {
337
set result ""
338
set markup [list]
339
set regexp {\033\[((?:\d+;)*\d+)?m}
340
+ set need_reset 0
341
while {[regexp -indices -start $start $regexp $line match code]} {
342
foreach {begin end} $match break
343
append result [string range $line $start [expr {$begin - 1}]]
343
- lappend markup [string length $result] \
344
- [eval [linsert $code 0 string range $line]]
344
+ set pos [string length $result]
345
+ set col [eval [linsert $code 0 string range $line]]
346
set start [incr end]
347
+ if {$col eq "0" || $col eq ""} {
348
+ if {!$need_reset} continue
349
+ set need_reset 0
350
+ } else {
351
+ set need_reset 1
352
+ }
353
+ lappend markup $pos $col
354
}
355
append result [string range $line $start end]
356
if {[llength $markup] < 4} {set markup {}}