<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_known_codes( s: Union[str, 'Colr'], unique: Optional[bool] = True, rgb_mode: Optional[bool] = False):
 """ Get all known escape codes from a string, and yield the explanations. """


    isdisabled = disabled()
    orderedcodes = tuple((c, get_known_name(c)) for c in get_codes(s))
    codesdone = set()  # type: Set[str]

    for code, codeinfo in orderedcodes:
        # Do the codes in order, but don't do the same code twice.

        if unique:
            if code in codesdone:
                continue
            codesdone.add(code)

        if codeinfo is None:
            continue
        codetype, name = codeinfo

        typedesc = '{:>13}: {!r:<23}'.format(codetype.title(), code)
        if codetype.startswith(('extended', 'rgb')):
            if isdisabled:
                codedesc = str(ColorCode(name, rgb_mode=rgb_mode))
            else:
                codedesc = ColorCode(name, rgb_mode=rgb_mode).example()
        else:
            codedesc = ''.join((
                code,
                str(name).lstrip('(').rstrip(')'),
                codes['style']['reset_all']
            ))

        yield ' '.join((
            typedesc,
            codedesc
        ))