1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/usr/bin/env python3
# Copyright 2017 vgm+dev@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()
|