aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2017-05-22 11:07:42 +0200
committerVG <vg@devys.org>2017-05-22 11:07:42 +0200
commit70f5f52982c60223f2b53a6467792c3c84514954 (patch)
tree73210e8c47928a7f6f64571ca574bec2ece2643d
parent6d0a4a8b006496202375b19238c46cea5829e9ed (diff)
downloadscripts-70f5f52982c60223f2b53a6467792c3c84514954.tar.gz
scripts-70f5f52982c60223f2b53a6467792c3c84514954.tar.bz2
scripts-70f5f52982c60223f2b53a6467792c3c84514954.zip
Add a script coloring weechat log to ansii
fun things like this can be done: tail -n2000 logfil.weechatlog | weechat-log2ansi | less -iR
-rwxr-xr-xscripts/weechat-log2ansi45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/weechat-log2ansi b/scripts/weechat-log2ansi
new file mode 100755
index 0000000..ba62129
--- /dev/null
+++ b/scripts/weechat-log2ansi
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# Copyright 2017 vg@devys.org
+# SPDX-License-Identifier: MIT
+
+
+'''
+This script is just for coloring weechat logs (mainly nick auto-coloring).
+
+Usage: weechat-log2ansi [OPTIONS...]
+ weechat-log2ansi -h|--help
+
+Options:
+ -h, --help Display this help message
+'''
+
+
+import sys
+
+
+import docopt
+
+
+def calculate_nickname_color(nickname):
+ total = 0
+ for letter in nickname:
+ total = ord(letter)
+ colors = ('1;30m', '31m', '1;31m', '32m', '1;32m', '33m', '1;33m', '34m',
+ '1;34m', '35m', '1;35m', '36m', '1;36m')
+ return colors[total % len(colors)]
+
+
+def main():
+ 'function called only when script invoked directly on command line'
+ args = docopt.docopt(__doc__)
+ for line in sys.stdin:
+ groups = line.split('\t')
+ print('\x1b[1m', groups[0], '\x1b[m \x1b[',
+ calculate_nickname_color(groups[1]),
+ '{:>13}'.format(groups[1]),
+ '\x1b[m ',
+ '\t'.join(groups[2:]), sep='', end='')
+
+
+if __name__ == '__main__':
+ main()