def isatty():
if isatty.no_tty:
return False
f = sys.stdout
if f.isatty():
return True
if not iswindows:
return False
# Check for a cygwin ssh pipe
buf = ctypes.create_string_buffer(1024)
h = msvcrt.get_osfhandle(f.fileno())
if get_file_type(h) != 3:
return False
ret = get_file_info_by_handle(h, 2, buf, ctypes.sizeof(buf))
if not ret:
raise ctypes.WinError()
data = buf.raw
name = data[4:].decode('utf-16').rstrip(u'\0')
parts = name.split('-')
return parts[0] == r'\cygwin' and parts[2].startswith('pty') and parts[4] == 'master'
评论列表
文章目录