Created
January 22, 2016 13:42
-
-
Save lukecampbell/00d1698d89a9ae877a12 to your computer and use it in GitHub Desktop.
Replaces terminal escape characters with a space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
def valid_character(i): | |
return ord(i) < 128 and (ord(i) > 31 or ord(i) == 10 or ord(i) == 0) | |
def main(args): | |
''' | |
Replaces terminal escape characters with a space | |
''' | |
with open(args.path, 'r') as f: | |
buf = f.read() | |
fixed = ''.join([i if valid_character(i) else ' ' for i in buf]) | |
with open(args.path, 'w') as f: | |
f.write(fixed) | |
return 0 | |
if __name__ == '__main__': | |
from argparse import ArgumentParser | |
parser = ArgumentParser(description=main.__doc__) | |
parser.add_argument('path', help='Path to file to be fixed') | |
args = parser.parse_args() | |
sys.exit(main(args)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment