diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-07 01:56:05 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-08 01:48:00 -0700 |
commit | 4763e230ab02bcf3e7db20dee23d42a02815bdb3 (patch) | |
tree | 34ccc612c212045e4d4ed38e8ccf94a7b15953d0 /tools/colorize | |
parent | 0c2de8979105e6b5a24be18d3241a609f9bfed8f (diff) | |
download | tmwa-4763e230ab02bcf3e7db20dee23d42a02815bdb3.tar.gz tmwa-4763e230ab02bcf3e7db20dee23d42a02815bdb3.tar.bz2 tmwa-4763e230ab02bcf3e7db20dee23d42a02815bdb3.tar.xz tmwa-4763e230ab02bcf3e7db20dee23d42a02815bdb3.zip |
Split script.cpp
Diffstat (limited to 'tools/colorize')
-rwxr-xr-x | tools/colorize | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tools/colorize b/tools/colorize index ae4cb56..ce6f410 100755 --- a/tools/colorize +++ b/tools/colorize @@ -12,6 +12,10 @@ def color(i): return '\x1b[%dm' % (90 + (i - 8)) def main(argv): + # can't change buffering on sys.stdout after creation using python APIs + # so do our own buffering + buffer = [] + colors = {} while argv: arg0 = argv[0] @@ -26,12 +30,13 @@ def main(argv): arg = argv[0] c = colors.get('', '') e = c and '\x1b[m' - print(c, arg, e, sep='', end=''), + buffer.extend([c, arg, e]) for arg in argv[1:]: c = colors.get(arg, '') e = c and '\x1b[m' - print(' ', c, arg, e, sep='', end=''), - print() + buffer.extend([' ', c, arg, e]) + buffer.append('\n') + sys.stdout.write(''.join(buffer)) sys.stdout.flush() os.execvp(argv[0], argv) |