'Turn a string input into a list of L{ColorText} elements.'

def parseString(self, str):

    if self.prepend:
        str = (self.prepend + str)
        self.prepend = ''
    parts = str.split('\x1b')
    if (len(parts) == 1):
        self.writeString(self.formatText(parts[0]))
    else:
        self.writeString(self.formatText(parts[0]))
        for s in parts[1:]:
            L = len(s)
            i = 0
            type = None
            while (i < L):
                if (s[i] not in (string.digits + '[;?')):
                    break
                i += 1
            if (not s):
                self.prepend = '\x1b'
                return
            if (s[0] != '['):
                self.writeString(self.formatText(s[(i + 1):]))
                continue
            else:
                s = s[1:]
                i -= 1
            if (i == (L - 1)):
                self.prepend = '\x1b['
                return
            type = _setmap.get(s[i], None)
            if (type is None):
                continue
            if (type == AnsiParser.COLOR_SET):
                self.parseColor(s[:(i + 1)])
                s = s[(i + 1):]
                self.writeString(self.formatText(s))
            elif (type == AnsiParser.CURSOR_SET):
                (cursor, s) = (s[:(i + 1)], s[(i + 1):])
                self.parseCursor(cursor)
                self.writeString(self.formatText(s))
            elif (type == AnsiParser.ERASE_SET):
                (erase, s) = (s[:(i + 1)], s[(i + 1):])
                self.parseErase(erase)
                self.writeString(self.formatText(s))
            elif (type == AnsiParser.MODE_SET):
                s = s[(i + 1):]
                self.writeString(self.formatText(s))
            elif (i == L):
                self.prepend = ('\x1b[' + s)
            else:
                log.msg(('Unhandled    ANSI    control    type:    %c' % (s[i],)))
                s = s[(i + 1):]
                self.writeString(self.formatText(s))
