def wrap_line(txt, width, wrap_prefix=None):
    """
    Word wrap a single line.

    :param str txt: the line to wrap
    :param int width: the maximum width of a wrapped line
    :returns str: the next wrapped line
    """
    if width is None or width <= 0:
        yield txt
    else:
        wrap_prefix = wrap_prefix or ''
        start = 0
        count = 0
        i = 0
        total = len(txt)
        first_line = True
        while i < total:
            esc_code = False
            prev = None
            while count <= width and i < total:
                c = txt[i]
                if c == '\x1b':
                    esc_code = True
                elif esc_code:
                    if c in 'ABCDEFGHJKSTfmnsulh':
                        esc_code = False
                else:
                    count += 1
                    if c in ' \t':
                        prev = i
                i += 1
            if i >= total:
                prev = i
            else:
                prev = prev or i
            if wrap_prefix and first_line:
                first_line = False
                width -= len(wrap_prefix)
                yield txt[start:prev]
            else:
                yield wrap_prefix + txt[start:prev]
            start = prev
            while start < total and txt[start] in '\t ':
                start += 1
            i = start
            count = 0
        if count:
            if not first_line:
                yield wrap_prefix + txt[start:]
            else:
                yield txt[start:]
