From: Bert Wesarg <bert.wesarg@googlemail.com>
To: Pat Thoyts <patthoyts@users.sourceforge.net>
Cc: Bert Wesarg <bert.wesarg@googlemail.com>,
"Shawn O . Pearce" <spearce@spearce.org>,
git@vger.kernel.org
Subject: [PATCH] git-gui: fix ANSI-color parsing
Date: Mon, 15 Nov 2010 11:00:33 +0100 [thread overview]
Message-ID: <1289815233-11391-1-git-send-email-bert.wesarg@googlemail.com> (raw)
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 reply other threads:[~2010-11-15 10:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-15 10:00 Bert Wesarg [this message]
2010-11-19 9:34 ` [PATCH] git-gui: fix ANSI-color parsing Pat Thoyts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1289815233-11391-1-git-send-email-bert.wesarg@googlemail.com \
--to=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
--cc=patthoyts@users.sourceforge.net \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).