def encode(code, readline=False):
    """ Adds escape and control characters for ANSI codes

    :param code: pick a constant, any constant
    :type code: int
    :param readline: add readline compatibility, which causes bugs in other formats
    :type content: unicode
    :return: ansi string
    :rtype: unicode
    """
    if readline:
        return '\x01\x1b[' + str(code) + 'm\x02'
    return '\x1b[' + str(code) + 'm'
