Add gst-debug-strip-color.py, a script to strip color codes
authorRené Stadler <mail@renestadler.de>
Thu, 13 Dec 2007 11:36:45 +0000 (13:36 +0200)
committerStefan Sauer <ensonic@users.sf.net>
Thu, 11 Sep 2014 18:51:43 +0000 (20:51 +0200)
debug-viewer/gst-debug-strip-color.py [new file with mode: 0755]

diff --git a/debug-viewer/gst-debug-strip-color.py b/debug-viewer/gst-debug-strip-color.py
new file mode 100755 (executable)
index 0000000..4b2d86c
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import sys
+import re
+
+def strip_color (input, output):
+
+    _escape = re.compile ("\x1b\\[[0-9;]*m")
+    # TODO: This can be optimized further!
+
+    for line in input:
+        while "\x1b" in line:
+            line = _escape.sub ("", line)
+        print output.write (line)
+
+def main ():
+
+    if len (sys.argv) == 1 or sys.argv[1] == "-":
+        strip_color (sys.stdin, sys.stdout)
+    else:
+        strip_color (file (sys.argv[1], "rb"), sys.stdout)
+
+if __name__ == "__main__":
+    main ()