当前位置: 首页>>代码示例>>Python>>正文


Python termios.TIOCGWINSZ属性代码示例

本文整理汇总了Python中termios.TIOCGWINSZ属性的典型用法代码示例。如果您正苦于以下问题:Python termios.TIOCGWINSZ属性的具体用法?Python termios.TIOCGWINSZ怎么用?Python termios.TIOCGWINSZ使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在termios的用法示例。


在下文中一共展示了termios.TIOCGWINSZ属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_termsize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def get_termsize():
    """Return terminal size as a tuple (height, width)."""
    try:
        # this works on unix machines
        import struct, fcntl, termios
        height, width = struct.unpack("hhhh",
                                      fcntl.ioctl(0,termios.TIOCGWINSZ,
                                                  "\000"*8))[0:2]
        if not (height and width):
            height, width = 24, 79
    except ImportError:
        # for windows machins, use default values
        # Does anyone know how to get the console size under windows?
        # One approach is:
        # http://code.activestate.com/recipes/440694/
        height, width = 24, 79
    return height, width 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:19,代码来源:progress_bar.py

示例2: resize_handler

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def resize_handler(self):
        """Send the new window size to conmon."""

        def wrapped(signum, frame):  # pylint: disable=unused-argument
            packed = fcntl.ioctl(self.pseudo_tty.stdout, termios.TIOCGWINSZ,
                                 struct.pack('HHHH', 0, 0, 0, 0))
            rows, cols, _, _ = struct.unpack('HHHH', packed)
            logging.debug('Resize window(%dx%d) using %s', rows, cols,
                          self.pseudo_tty.control_socket)

            # TODO: Need some kind of timeout in case pipe is blocked
            with open(self.pseudo_tty.control_socket, 'w') as skt:
                # send conmon window resize message
                skt.write('1 {} {}\n'.format(rows, cols))

        return wrapped 
开发者ID:containers,项目名称:python-podman,代码行数:18,代码来源:_containers_attach.py

示例3: _get_terminal_size_linux

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _get_terminal_size_linux():
    def ioctl_GWINSZ(fd):
        try:
            import fcntl
            import termios
            cr = struct.unpack('hh',
                               fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
            return cr
        except:
            pass
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    if not cr:
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = ioctl_GWINSZ(fd)
            os.close(fd)
        except:
            pass
    if not cr:
        try:
            cr = (os.environ['LINES'], os.environ['COLUMNS'])
        except:
            return None
    return int(cr[1]), int(cr[0]) 
开发者ID:aaronjanse,项目名称:asciidots,代码行数:26,代码来源:terminalsize.py

示例4: get_terminal_size

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def get_terminal_size():
        fallback = (80, 24)
        try:
            from shutil import get_terminal_size
        except ImportError:
            try:
                import termios
                import fcntl
                import struct
                call = fcntl.ioctl(0, termios.TIOCGWINSZ, "\x00"*8)
                height, width = struct.unpack("hhhh", call)[:2]
            except (SystemExit, KeyboardInterrupt):
                raise
            except:
                width = int(os.environ.get('COLUMNS', fallback[0]))
                height = int(os.environ.get('COLUMNS', fallback[1]))
            # Work around above returning width, height = 0, 0 in Emacs
            width = width if width != 0 else fallback[0]
            height = height if height != 0 else fallback[1]
            return width, height
        else:
            return get_terminal_size(fallback) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:24,代码来源:pdbpp.py

示例5: _getTerminalSize_linux

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _getTerminalSize_linux():
    def ioctl_GWINSZ(fd):
        try:
            import fcntl, termios, struct, os
            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,'1234'))
        except:
            return None
        return cr
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    if not cr:
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = ioctl_GWINSZ(fd)
            os.close(fd)
        except:
            pass
    if not cr:
        try:
            cr = (env['LINES'], env['COLUMNS'])
        except:
            return None
    return int(cr[1]), int(cr[0]) 
开发者ID:euphrat1ca,项目名称:fuzzdb-collect,代码行数:24,代码来源:consle_width.py

示例6: _get_terminal_size_linux

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _get_terminal_size_linux():
  def ioctl_GWINSZ(fd):
    try:
      import fcntl, termios, struct, os
      cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,'1234'))
    except:
      return None
    return cr
  cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
  if not cr:
    try:
      fd = os.open(os.ctermid(), os.O_RDONLY)
      cr = ioctl_GWINSZ(fd)
      os.close(fd)
    except:
      pass
  if not cr:
    try:
      cr = (env['LINES'], env['COLUMNS'])
    except:
      return None
  return int(cr[1]), int(cr[0]) 
开发者ID:joxeankoret,项目名称:maltindex,代码行数:24,代码来源:terminal.py

示例7: size

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def size(fileno):
    """Current terminal height and width (lines and columns).

    :params int fileno: file-descriptor
    :returns: Tuple of two integers - lines and columns respectively.
              ``(None, None)`` if ``fileno`` is not a terminal
    """
    if not isatty(fileno):
        return None, None

    try:
        size = struct.unpack(
            '2h', fcntl.ioctl(fileno, termios.TIOCGWINSZ, '    '))
    except Exception:
        size = (os.getenv('LINES', 25), os.getenv('COLUMNS', 80))

    return size 
开发者ID:edgedb,项目名称:edgedb,代码行数:19,代码来源:term.py

示例8: _getTerminalSize_linux

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _getTerminalSize_linux():
    def ioctl_GWINSZ(fd):
        try:
            import fcntl, termios, struct, os
            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
        except:
            return None
        return cr

    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    if not cr:
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = ioctl_GWINSZ(fd)
            os.close(fd)
        except:
            pass
    if not cr:
        try:
            cr = (os.environ['LINES'], os.environ['COLUMNS'])
        except:
            return None
    return int(cr[1]), int(cr[0]) 
开发者ID:halilozercan,项目名称:pget,代码行数:25,代码来源:term.py

示例9: _winsize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _winsize(fd):
        """
        Return named tuple describing size of the terminal by ``fd``.

        If the given platform does not have modules :mod:`termios`,
        :mod:`fcntl`, or :mod:`tty`, window size of 80 columns by 25
        rows is always returned.

        :arg int fd: file descriptor queries for its window size.
        :raises IOError: the file descriptor ``fd`` is not a terminal.
        :rtype: WINSZ

        WINSZ is a :class:`collections.namedtuple` instance, whose structure
        directly maps to the return value of the :const:`termios.TIOCGWINSZ`
        ioctl return value. The return parameters are:

            - ``ws_row``: width of terminal by its number of character cells.
            - ``ws_col``: height of terminal by its number of character cells.
            - ``ws_xpixel``: width of terminal by pixels (not accurate).
            - ``ws_ypixel``: height of terminal by pixels (not accurate).
        """
        if HAS_TTY:
            data = fcntl.ioctl(fd, termios.TIOCGWINSZ, WINSZ._BUF)
            return WINSZ(*struct.unpack(WINSZ._FMT, data))
        return WINSZ(ws_row=25, ws_col=80, ws_xpixel=0, ws_ypixel=0) 
开发者ID:QData,项目名称:deepWordBug,代码行数:27,代码来源:terminal.py

示例10: size

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def size(fd):
    """
    Return a tuple (rows,cols) representing the size of the TTY `fd`.

    The provided file descriptor should be the stdout stream of the TTY.

    If the TTY size cannot be determined, returns None.
    """

    if not os.isatty(fd.fileno()):
        return None

    try:
        dims = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, 'hhhh'))
    except:
        try:
            dims = (os.environ['LINES'], os.environ['COLUMNS'])
        except:
            return None

    return dims 
开发者ID:QData,项目名称:deepWordBug,代码行数:23,代码来源:tty.py

示例11: _get_terminal_width_ioctl

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _get_terminal_width_ioctl(stdout):
    from fcntl import ioctl
    import termios

    try:
        # winsize structure has 4 unsigned short fields
        winsize = b'\0' * struct.calcsize('hhhh')
        try:
            winsize = ioctl(stdout, termios.TIOCGWINSZ, winsize)
        except IOError:
            return None
        except TypeError:
            # this is raised in unit tests as stdout is sometimes a StringIO
            return None
        winsize = struct.unpack('hhhh', winsize)
        columns = winsize[1]
        if not columns:
            return None
        return columns
    except IOError:
        return None 
开发者ID:openstack,项目名称:cliff,代码行数:23,代码来源:utils.py

示例12: getTerminalSize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def getTerminalSize():
    env = os.environ
    def ioctl_GWINSZ(fd):
        try:
            import fcntl, termios, struct
            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
        except:
            return None
        return cr
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    if not cr:
        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]) 
开发者ID:im-tomu,项目名称:valentyusb,代码行数:22,代码来源:sdiff.py

示例13: _get_terminal_size_linux

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _get_terminal_size_linux():
  def ioctl_GWINSZ(fd):
    try:
      import fcntl
      import termios
      cr = struct.unpack('hh',
                 fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
      return cr
    except:
      pass
  cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
  if not cr:
    try:
      fd = os.open(os.ctermid(), os.O_RDONLY)
      cr = ioctl_GWINSZ(fd)
      os.close(fd)
    except:
      pass
  if not cr:
    try:
      cr = (os.environ['LINES'], os.environ['COLUMNS'])
    except:
      return None
  return int(cr[1]), int(cr[0]) 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:26,代码来源:terminalsize.py

示例14: handleResize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def handleResize(self, signum, frame):
        h,w=array('h', ioctl(sys.stderr,termios.TIOCGWINSZ,'\0'*8))[:2]
        self.term_width = w 
开发者ID:svviz,项目名称:svviz,代码行数:5,代码来源:multiprocessor.py

示例15: _get_terminal_size_linux

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCGWINSZ [as 别名]
def _get_terminal_size_linux(self):
        def ioctl_GWINSZ(fd):
            try:
                import fcntl
                import termios

                cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234"))
                return cr
            except:
                pass

        cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
        if not cr:
            try:
                fd = os.open(os.ctermid(), os.O_RDONLY)
                cr = ioctl_GWINSZ(fd)
                os.close(fd)
            except:
                pass

        if not cr:
            try:
                cr = (os.environ["LINES"], os.environ["COLUMNS"])
            except:
                return None

        return int(cr[1]), int(cr[0]) 
开发者ID:sdispater,项目名称:clikit,代码行数:29,代码来源:terminal.py


注:本文中的termios.TIOCGWINSZ属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。