#!/usr/bin/python

from __future__ import print_function

import sys
import re
import irssilib as il

maxlen = 0
hits = {}

counts = {'grey': 0, 'blue': 0, 'green': 0, 'cyan': 0, 'red': 0, 'magenta': 0}
allocated  = {}

def format_chan(text, channel=None):
    global maxlen
    chanstr = ''

    if channel != None:
        maxlen = il.getmaxlen(channel, maxlen)
        chancolor = il.getcolor(channel, allocated, counts, hits)
        il.uplogs(chancolor, hits)
        chanstr = il.getmaxpad(channel, maxlen) + chancolor + channel + il.clearseq + ' '

    return chanstr + text

def main():
    chanmatcher = re.compile('^((#[^\t]+)\t)?(.*)')
    try:
        line = sys.stdin.readline()
        while line:
            result = chanmatcher.match(line)
            if result:
                line = format_chan(result.group(3) + '\n', result.group(2))
            print(line, end='')
            sys.stdout.flush()
            line = sys.stdin.readline()
    except KeyboardInterrupt:
        pass

if __name__ == '__main__':
    main()

@@ -213,16 +213,34 @@
   = %7B%7D%0A%0A
+textmatcher = %7B%7D%0A%0A
 def form
@@ -247,20 +247,21 @@
 at_chan(
-text
+after
 , channe
@@ -568,16 +568,302 @@
  + ' '%0A%0A
+        for u,c in allocated.items():%0A            if u not in textmatcher:%0A                textmatcher%5Bu%5D = re.compile('((' + il.crankseq + ')%7C(%5B%5E%5Cw%5D)%7C(%5E))(' + re.escape(u) + ')((%5B%5E%5Cw%5D)%7C($))')%0A%0A            after = re.sub(textmatcher%5Bu%5D, '%5C%5C1' + c + '%5C%5C5' + il.clearseq + '%5C%5C6', after)%0A%0A
     retu
@@ -875,20 +875,21 @@
 anstr + 
-text
+after
 %0A%0Adef ma

add text colorizing for channel names