_print.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:senf 作者: quodlibet 项目源码 文件源码
def supports_ansi_escape_codes(fd):
    """Returns whether the output device is capable of interpreting ANSI escape
    codes when :func:`print_` is used.

    Args:
        fd (int): file descriptor (e.g. ``sys.stdout.fileno()``)
    Returns:
        `bool`
    """

    if os.isatty(fd):
        return True

    if not is_win:
        return False

    # Check for cygwin/msys terminal
    handle = winapi._get_osfhandle(fd)
    if handle == winapi.INVALID_HANDLE_VALUE:
        return False

    if winapi.GetFileType(handle) != winapi.FILE_TYPE_PIPE:
        return False

    file_name = _get_file_name_for_handle(handle)
    match = re.match(
        "^\\\\(cygwin|msys)-[a-z0-9]+-pty[0-9]+-(from|to)-master$", file_name)
    return match is not None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号