def decorate(string, *formats):
    """Decorates a string using ANSI escape codes given some format enums.

    Calling len(s) on a string which has been decorated in this manner will not
    return the printed width. Call len(ansi_undecorate(s)) to achieve this.

    Args:
        string:     string to decorate.
        formats:    any number of format enums to apply to the string.

    Returns:
        Decorated representation of string.
    """
    # If no formats have been given, do nothing
    if not formats:
        return string
    # Otherwise construct the start code
    start = '\033['
    for fmt in formats:
        start += str(fmt) + ';'
    # Remove final ';', append an 'm'
    start = start[:-1] + 'm'
    # Hard coded reset code to finish
    end = '\033[0m'
    return start + string + end