def __new__(cls, *args, **kwargs):
        """Parse color markup and instantiate."""
        keep_tags = kwargs.pop('keep_tags', False)

        # Parse string.
        value_markup = args[0] if args else PARENT_CLASS()  # e.g. '{red}test{/red}'
        value_colors, value_no_colors = parse_input(value_markup, ANSICodeMapping.DISABLE_COLORS, keep_tags)
        color_index = build_color_index(value_colors)

        # Instantiate.
        color_args = [cls, value_colors] + list(args[1:])
        instance = PARENT_CLASS.__new__(*color_args, **kwargs)

        # Add additional attributes and return.
        instance.value_colors = value_colors
        instance.value_no_colors = value_no_colors
        instance.has_colors = value_colors != value_no_colors
        instance.color_index = color_index
        return instance
def __new__ ( cls , * args , ** kwargs ) : keep_tags = kwargs . pop ( 'keep_tags' , False ) value_markup = args [ 0 ] if args else PARENT_CLASS ( ) value_colors , value_no_colors = parse_input ( value_markup , ANSICodeMapping . DISABLE_COLORS , keep_tags ) color_index = build_color_index ( value_colors ) color_args = [ cls , value_colors ] + list ( args [ 1 : ] ) instance = PARENT_CLASS . __new__ ( * color_args , ** kwargs ) instance . value_colors = value_colors instance . value_no_colors = value_no_colors instance . has_colors = value_colors != value_no_colors instance . color_index = color_index return instance
Parse color markup and instantiate.