diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-02-06 11:18:14 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-02-06 11:18:37 -0800 |
commit | 0177b97ba96407e00636711b1aa71b8ddf3f9ed6 (patch) | |
tree | cbaf245899610d609094ab087d8b9586376cb2b7 /tools/colorize | |
parent | 9215c35975be745628e8188473154c7e476add55 (diff) | |
download | tmwa-0177b97ba96407e00636711b1aa71b8ddf3f9ed6.tar.gz tmwa-0177b97ba96407e00636711b1aa71b8ddf3f9ed6.tar.bz2 tmwa-0177b97ba96407e00636711b1aa71b8ddf3f9ed6.tar.xz tmwa-0177b97ba96407e00636711b1aa71b8ddf3f9ed6.zip |
Add a little color
Diffstat (limited to 'tools/colorize')
-rwxr-xr-x | tools/colorize | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/colorize b/tools/colorize new file mode 100755 index 0000000..ae4cb56 --- /dev/null +++ b/tools/colorize @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import os +import sys + +def color(i): + if 0 <= i < 8: + return '\x1b[%dm' % (30 + i) + if 8 <= i < 16: + return '\x1b[%dm' % (90 + (i - 8)) + +def main(argv): + colors = {} + while argv: + arg0 = argv[0] + del argv[0] + if arg0 == ':': + break + if ':' not in arg0: + continue + c, w = arg0.split(':', 1) + colors[w] = color(int(c)) + if 1: + arg = argv[0] + c = colors.get('', '') + e = c and '\x1b[m' + print(c, arg, e, sep='', end=''), + for arg in argv[1:]: + c = colors.get(arg, '') + e = c and '\x1b[m' + print(' ', c, arg, e, sep='', end=''), + print() + sys.stdout.flush() + os.execvp(argv[0], argv) + +if __name__ == '__main__': + main(sys.argv[:]) |