Example #1
0
 def add_elem(s, c, p):
     if s:
         p += s
         sl = self._style_line(self.style, self.pstyle)
         if sl:
             e = ConsoleMessage.construct(('span', sl, s))
             c.contents.append(e)
             c = e
             self.pstyle = copy(self.style)
         else:
             e = ConsoleMessage.construct(s)
             c.contents.append(e)
     return c, p
Example #2
0
 def parse(self, line):
     """Convert a line from a mud server into a ConsoleMessage. Also return
     a line stripped of escape codes."""
         
     line = line.rstrip('\r\n')
     l = 0
     r = ConsoleMessage.construct(('div', 'mud', []))
     c = r
     p = ''
     self._reset(self.pstyle)
     def add_elem(s, c, p):
         if s:
             p += s
             sl = self._style_line(self.style, self.pstyle)
             if sl:
                 e = ConsoleMessage.construct(('span', sl, s))
                 c.contents.append(e)
                 c = e
                 self.pstyle = copy(self.style)
             else:
                 e = ConsoleMessage.construct(s)
                 c.contents.append(e)
         return c, p
     for m in self.sgr_regex.finditer(line):
         dont_strip = False
         c, p = add_elem(line[l:m.start()], c, p)
         for g in m.groups():
             if g is None:
                 continue
             a = self._attr(int(g))
             if a == 'reset':
                 self._reset(self.style)
                 c = r
             elif a == 'unknown':
                 if not self.strip_unsupported:
                     dont_strip = True
             elif a in fg_colors:
                 self.style.fg = a
             elif a in bg_colors:
                 self.style.bg = a[:-3] if a.endswith('_bg') else a
             else:
                 setattr(self.style, a, True)
         if not dont_strip:
             l = m.end()
     c, p = add_elem(line[l:], c, p)
     return (r, p)
Example #3
0
 def _elem(self, text):
     return ConsoleMessage.construct()