def terminal_len(value):
    """Returns the length of the string it would be when displayed.

    Attempts to decode the string as UTF-8 first if it's a bytestring.
    """
    if isinstance(value, bytes):
        value = value.decode("utf8", "ignore")

    return len(value)
Returns the length of the string it would be when displayed.

    Attempts to decode the string as UTF-8 first if it's a bytestring.
    
src/livestreamer_cli/utils/progress.py