Added capability to filter ANSI escape sequences out of output strings. This is limited to color sequences at the moment.

Wed, 06 Jul 2016 19:27:15 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 06 Jul 2016 19:27:15 +0200
changeset 5020
d0afdfd8e45b
parent 5015
ca1d44f0f6b2
child 5022
effdfd3bce96

Added capability to filter ANSI escape sequences out of output strings. This is limited to color sequences at the moment.

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Utilities.__init__.html file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/HgDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesHeaderDialog.py file | annotate | diff | comparison | revisions
QScintilla/Shell.py file | annotate | diff | comparison | revisions
UI/LogView.py file | annotate | diff | comparison | revisions
Utilities/__init__.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Sun Jul 03 16:34:45 2016 +0200
+++ b/APIs/Python3/eric6.api	Wed Jul 06 19:27:15 2016 +0200
@@ -9210,6 +9210,7 @@
 eric6.Utilities.extractFlags?4(text)
 eric6.Utilities.extractFlagsFromFile?4(filename)
 eric6.Utilities.extractLineFlags?4(line, startComment=")
+eric6.Utilities.filterAnsiSequences?4(txt)
 eric6.Utilities.fromNativeSeparators?4(path)
 eric6.Utilities.generateDistroInfo?4(linesep='\n')
 eric6.Utilities.generatePluginsVersionInfo?4(linesep='\n')
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sun Jul 03 16:34:45 2016 +0200
+++ b/Documentation/Help/source.qhp	Wed Jul 06 19:27:15 2016 +0200
@@ -16231,6 +16231,7 @@
       <keyword name="factory" id="factory" ref="eric6.ViewManager.__init__.html#factory" />
       <keyword name="fetch (Module)" id="fetch (Module)" ref="eric6.Plugins.VcsPlugins.vcsMercurial.FetchExtension.fetch.html" />
       <keyword name="filename_match" id="filename_match" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.pep8.html#filename_match" />
+      <keyword name="filterAnsiSequences" id="filterAnsiSequences" ref="eric6.Utilities.__init__.html#filterAnsiSequences" />
       <keyword name="filterCharsFromFilename" id="filterCharsFromFilename" ref="eric6.Helpviewer.HelpUtilities.html#filterCharsFromFilename" />
       <keyword name="filterCharsFromFilename" id="filterCharsFromFilename" ref="eric6.WebBrowser.Tools.WebBrowserTools.html#filterCharsFromFilename" />
       <keyword name="findPythonInterpreters" id="findPythonInterpreters" ref="eric6.Globals.__init__.html#findPythonInterpreters" />
--- a/Documentation/Source/eric6.Utilities.__init__.html	Sun Jul 03 16:34:45 2016 +0200
+++ b/Documentation/Source/eric6.Utilities.__init__.html	Wed Jul 06 19:27:15 2016 +0200
@@ -91,6 +91,9 @@
 <td><a href="#extractLineFlags">extractLineFlags</a></td>
 <td>Function to extract flags starting and ending with '__' from a line comment.</td>
 </tr><tr>
+<td><a href="#filterAnsiSequences">filterAnsiSequences</a></td>
+<td>Function to filter out ANSI escape sequences (color only).</td>
+</tr><tr>
 <td><a href="#fromNativeSeparators">fromNativeSeparators</a></td>
 <td>Function returning a path, that is using "/" separator characters.</td>
 </tr><tr>
@@ -730,6 +733,29 @@
 </dl>
 <div align="right"><a href="#top">Up</a></div>
 <hr /><hr />
+<a NAME="filterAnsiSequences" ID="filterAnsiSequences"></a>
+<h2>filterAnsiSequences</h2>
+<b>filterAnsiSequences</b>(<i>txt</i>)
+<p>
+    Function to filter out ANSI escape sequences (color only).
+</p><dl>
+<dt><i>txt</i> (str)</dt>
+<dd>
+text to be filtered
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+text without ANSI escape sequences
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+str
+</dd>
+</dl>
+<div align="right"><a href="#top">Up</a></div>
+<hr /><hr />
 <a NAME="fromNativeSeparators" ID="fromNativeSeparators"></a>
 <h2>fromNativeSeparators</h2>
 <b>fromNativeSeparators</b>(<i>path</i>)
--- a/Plugins/VcsPlugins/vcsMercurial/HgDialog.py	Sun Jul 03 16:34:45 2016 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/HgDialog.py	Wed Jul 06 19:27:15 2016 +0200
@@ -23,6 +23,7 @@
 from .Ui_HgDialog import Ui_HgDialog
 
 import Preferences
+import Utilities
 
 
 class HgDialog(QDialog, Ui_HgDialog):
@@ -221,7 +222,7 @@
         
         @param out output to be shown (string)
         """
-        self.resultbox.insertPlainText(out)
+        self.resultbox.insertPlainText(Utilities.filterAnsiSequences(out))
         self.resultbox.ensureCursorVisible()
         
         # check for a changed project file
@@ -253,7 +254,7 @@
         @param out error to be shown (string)
         """
         self.errorGroup.show()
-        self.errors.insertPlainText(out)
+        self.errors.insertPlainText(Utilities.filterAnsiSequences(out))
         self.errors.ensureCursorVisible()
         
         QCoreApplication.processEvents()
--- a/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesHeaderDialog.py	Sun Jul 03 16:34:45 2016 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesHeaderDialog.py	Wed Jul 06 19:27:15 2016 +0200
@@ -22,6 +22,8 @@
 
 from .Ui_HgQueuesHeaderDialog import Ui_HgQueuesHeaderDialog
 
+import Utilities
+
 
 class HgQueuesHeaderDialog(QDialog, Ui_HgQueuesHeaderDialog):
     """
@@ -173,7 +175,7 @@
         
         @param out output to be shown (string)
         """
-        self.messageEdit.appendPlainText(out)
+        self.messageEdit.appendPlainText(Utilities.filterAnsiSequences(out))
     
     def __readStderr(self):
         """
@@ -194,4 +196,4 @@
         @param out error to be shown (string)
         """
         self.messageEdit.appendPlainText(self.tr("Error: "))
-        self.messageEdit.appendPlainText(out)
+        self.messageEdit.appendPlainText(Utilities.filterAnsiSequences(out))
--- a/QScintilla/Shell.py	Sun Jul 03 16:34:45 2016 +0200
+++ b/QScintilla/Shell.py	Wed Jul 06 19:27:15 2016 +0200
@@ -25,6 +25,8 @@
 
 import Preferences
 
+import Utilities
+
 import UI.PixmapCache
 
 from Debugger.DebugClientCapabilities import HasCompleter
@@ -765,7 +767,7 @@
         """
         line, col = self.__getEndPos()
         self.setCursorPosition(line, col)
-        self.insert(s)
+        self.insert(Utilities.filterAnsiSequences(s))
         self.prline, self.prcol = self.getCursorPosition()
         self.ensureCursorVisible()
         self.ensureLineVisible(self.prline)
@@ -897,7 +899,7 @@
         @param s text to be inserted (string)
         """
         line, col = self.getCursorPosition()
-        self.insertAt(s, line, col)
+        self.insertAt(Utilities.filterAnsiSequences(s), line, col)
         self.setCursorPosition(line, col + len(s))
         
     def __insertTextAtEnd(self, s):
@@ -908,7 +910,7 @@
         """
         line, col = self.__getEndPos()
         self.setCursorPosition(line, col)
-        self.insert(s)
+        self.insert(Utilities.filterAnsiSequences(s))
         self.prline, _ = self.getCursorPosition()
         
     def __insertTextNoEcho(self, s):
@@ -1742,6 +1744,7 @@
         
         @param txt text to be inserted (string)
         """
+        txt = Utilities.filterAnsiSequences(txt)
         length = len(txt)
         line, col = self.getCursorPosition()
         self.insertAt(txt, line, col)
--- a/UI/LogView.py	Sun Jul 03 16:34:45 2016 +0200
+++ b/UI/LogView.py	Wed Jul 06 19:27:15 2016 +0200
@@ -18,6 +18,7 @@
 
 import UI.PixmapCache
 import Preferences
+import Utilities
 
 
 class LogViewer(QWidget):
@@ -156,7 +157,7 @@
             self.setCurrentCharFormat(self.cErrorFormat)
         else:
             self.setCurrentCharFormat(self.cNormalFormat)
-        self.insertPlainText(txt)
+        self.insertPlainText(Utilities.filterAnsiSequences(txt))
         self.ensureCursorVisible()
         
     def __filterMessage(self, message, isErrorMessage=False):
@@ -169,6 +170,8 @@
         @return flag indicating that the message should be filtered out
             (boolean)
         """
+        message = Utilities.filterAnsiSequences(message)
+        
         if isErrorMessage:
             filters = self.__stderrFilter + self.__stdxxxFilter
         else:
--- a/Utilities/__init__.py	Sun Jul 03 16:34:45 2016 +0200
+++ b/Utilities/__init__.py	Wed Jul 06 19:27:15 2016 +0200
@@ -678,6 +678,28 @@
     return flags
 
 
+def filterAnsiSequences(txt):
+    """
+    Function to filter out ANSI escape sequences (color only).
+    
+    @param txt text to be filtered
+    @type str
+    @return text without ANSI escape sequences
+    @rtype str
+    """
+    ntxt = txt[:]
+    while True:
+        start = ntxt.find("\33[")    # find escape character
+        if start == -1:
+            break
+        end = ntxt.find("m", start)
+        if end == -1:
+            break
+        ntxt = ntxt[:start] + ntxt[end + 1:]
+    
+    return ntxt
+
+
 def toNativeSeparators(path):
     """
     Function returning a path, that is using native separator characters.

eric ide

mercurial