changeset 53:fc29a1d8901f

Display ctrl characters in ^[char] notation to avoid them messing up the display (based on a patch provided by Risto Kankkunen <risto.kankkunen@iki.fi>)
author Mark Edgington <edgimar@gmail.com>
date Tue, 30 Jun 2009 23:04:23 +0200
parents 22a8bc9f4fd8
children 0a2eebee219c
files crecord/chunk_selector.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/crecord/chunk_selector.py
+++ b/crecord/chunk_selector.py
@@ -425,6 +425,9 @@
         """
         # preprocess the text, converting tabs to spaces
         text = text.expandtabs(4)
+        # Strip \n, and convert control characters to ^[char] representation
+        text = re.sub(r'[\x00-\x08\x0a-\x1f]',
+                lambda m:'^'+chr(ord(m.group())+64), text.strip('\n'))
 
         if pair is not None:
             colorPair = pair
@@ -615,7 +618,7 @@
 
         # print out lines of the chunk preceeding changed-lines
         for line in hunk.before:
-            lineStr = " "*(self.hunkLineIndentNumChars + len(checkBox)) + line.strip("\n")
+            lineStr = " "*(self.hunkLineIndentNumChars + len(checkBox)) + line
             outStr += self.printString(self.chunkpad, lineStr, toWin=toWin)
 
         return outStr
@@ -629,7 +632,7 @@
         # a bit superfluous, but to avoid hard-coding indent amount
         checkBox = self.getStatusPrefixString(hunk)
         for line in hunk.after:
-            lineStr = " "*(indentNumChars + len(checkBox)) + line.strip("\n")
+            lineStr = " "*(indentNumChars + len(checkBox)) + line
             outStr += self.printString(self.chunkpad, lineStr, toWin=toWin)
 
         return outStr