From 70f5f52982c60223f2b53a6467792c3c84514954 Mon Sep 17 00:00:00 2001 From: VG Date: Mon, 22 May 2017 11:07:42 +0200 Subject: Add a script coloring weechat log to ansii fun things like this can be done: tail -n2000 logfil.weechatlog | weechat-log2ansi | less -iR --- scripts/weechat-log2ansi | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 scripts/weechat-log2ansi (limited to 'scripts') 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() -- cgit v1.2.3