def strip_ansi(text, c1=False, osc=False):
    ''' Strip ANSI escape sequences from a portion of text.
        https://stackoverflow.com/a/38662876/450917

        Arguments:
            line: str
            osc: bool  - include OSC commands in the strippage.
            c1:  bool  - include C1 commands in the strippage.

        Notes:
            Enabling c1 and osc stripping is less efficient and the two options
            can mildly conflict with one another.
            The less problematic order was chosen, so there may still be rare
            C1 OSC fragments left over.
    '''
    text = ansi_csi0_finder.sub('', text)
    if osc:
        text = ansi_osc0_finder.sub('', text)
    if c1:
        text = ansi_csi1_finder.sub('', text)  # go first, less destructive
        if osc:
            text = ansi_osc1_finder.sub('', text)
    return text