Given an input `iterator` and the character that started an escape
    sequence, consume the whole escape sequence and return it.
    
    May raise StartEscapeSequenceException if a new escape sequence
    is started midway.
    
    The escape sequence is returned as an unicode string and is always
    formatted as if the extended format (ESC + [) had been used.

def consume_escape_sequence(iterator, starter):
    """Given an input `iterator` and the character that started an escape
    sequence, consume the whole escape sequence and return it.
    
    May raise StartEscapeSequenceException if a new escape sequence
    is started midway.
    
    The escape sequence is returned as an unicode string and is always
    formatted as if the extended format (ESC + [) had been used."""

    seq = [u'['] if is_char_single_character_csi(starter) else [next(iterator)]
    raise_if_start_escape_sequence(seq[-1])

    if seq[-1] == u'[':
        seq.append(next(iterator))
        raise_if_start_escape_sequence(seq[-1])
        while not (64 <= ord(seq[-1]) <= 126 or seq[-1] == 36):
            seq.append(next(iterator))
            raise_if_start_escape_sequence(seq[-1])
    elif seq[-1] == u'O': # read 1 more byte
        seq.append(next(iterator))
        raise_if_start_escape_sequence(seq[-1])
    else:
        pass

    return u'\x1b' + u''.join(seq)