當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。