def getTerminalSize():
"""
returns the terminal width and height
:return: the terminal width and height
"""
import os
env = os.environ
def ioctl_GWINSZ(fdi):
# noinspection PyBroadException
try:
import fcntl
import termios
import struct
cri = struct.unpack('hh', fcntl.ioctl(fdi, termios.TIOCGWINSZ, '1234'))
except:
return
return cri
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
# noinspection PyBroadException
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
cr = (env.get('LINES', 25), env.get('COLUMNS', 80))
return int(cr[1]), int(cr[0])
评论列表
文章目录