log.py 文件源码

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

项目:outis 作者: SySS-Research 项目源码 文件源码
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])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号