git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-gui: fix ANSI-color parsing

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Nov 15, 2010, 10:00 UTC
Message-ID
<1289815233-11391-1-git-send-email-bert.wesarg@googlemail.com>

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>
---
 git-gui/lib/diff.tcl |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
index dcf0711..0579fa6 100644
--- a/git-gui/lib/diff.tcl
+++ b/git-gui/lib/diff.tcl
@@ -337,12 +337,20 @@ proc parse_color_line {line} {
 	set result ""
 	set markup [list]
 	set regexp {\033\[((?:\d+;)*\d+)?m}
+	set need_reset 0
 	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 pos [string length $result]
+		set col [eval [linsert $code 0 string range $line]]
 		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]
 	if {[llength $markup] < 4} {set markup {}}
-- 
tg: (6f10c41..) bw/git-gui/fix-ansi-color-parsing (depends on: master)
Next: Pat Thoyts
Message 1 of 2 in “git-gui: fix ANSI-color parsing”
  1. git-gui: fix ANSI-color parsingBert Wesarg, Nov 15, 2010
  2. Pat ThoytsNov 19, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.