summaryrefslogtreecommitdiff
path: root/gst-debug-strip-color.py
blob: ccc184fbd15ee068c3156d043398883d11f2c543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
        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 ()