INNER CODE UNIT · Python

add_color_to_formatter_class

hartwork/git-delete-merged-branches · git_delete_merged_branches/_argparse_color.py:27

def add_color_to_formatter_class(formatter_class):
    class_name = formatter_class.__name__.replace("Formatter", "ColorFormatter")

    class Class(formatter_class):
        def format_help(self):
            text = super().format_help()
            for pattern, replacement in _SUBSTITUTIONS:
                matcher = re.compile(pattern, flags=re.MULTILINE)
                text = matcher.sub(replacement, text)
            return text

    Class.__name__ = class_name

    return Class

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…