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


Python termios.TIOCSWINSZ属性代码示例

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


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

示例1: setwinsize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def setwinsize(self, rows, cols):

        '''This sets the terminal window size of the child tty. This will cause
        a SIGWINCH signal to be sent to the child. This does not change the
        physical window size. It changes the size reported to TTY-aware
        applications like vi or curses -- applications that respond to the
        SIGWINCH signal. '''

        # Some very old platforms have a bug that causes the value for
        # termios.TIOCSWINSZ to be truncated. There was a hack here to work
        # around this, but it caused problems with newer platforms so has been
        # removed. For details see https://github.com/pexpect/pexpect/issues/39
        TIOCSWINSZ = getattr(termios, 'TIOCSWINSZ', -2146929561)
        # Note, assume ws_xpixel and ws_ypixel are zero.
        s = struct.pack('HHHH', rows, cols, 0, 0)
        fcntl.ioctl(self.fileno(), TIOCSWINSZ, s) 
开发者ID:c-amr,项目名称:camr,代码行数:18,代码来源:__init__.py

示例2: MatchWindowSize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def MatchWindowSize(master, slave):
  """Keep window sizes of two terminals in sync.

  Copy window size information from one terminal to another and
  register a signal hander to update window size information on
  the second terminal when window size of the first changes.

  Args:
    master: file descriptor of the terminal to observe.
    slave: file descriptor of the terminal to update.

  Returns:
    None.
  """

  def _CopyWindowSize():
    window_size = fcntl.ioctl(master, termios.TIOCGWINSZ, '00000000')
    fcntl.ioctl(slave, termios.TIOCSWINSZ, window_size)
    signal.signal(signal.SIGWINCH, lambda s, f: _CopyWindowSize())

  _CopyWindowSize() 
开发者ID:google,项目名称:ashier,代码行数:23,代码来源:terminal.py

示例3: test_ioctl_signed_unsigned_code_param

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def test_ioctl_signed_unsigned_code_param(self):
        if not pty:
            raise TestSkipped('pty module required')
        mfd, sfd = pty.openpty()
        try:
            if termios.TIOCSWINSZ < 0:
                set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
                set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffffL
            else:
                set_winsz_opcode_pos = termios.TIOCSWINSZ
                set_winsz_opcode_maybe_neg, = struct.unpack("i",
                        struct.pack("I", termios.TIOCSWINSZ))

            # We're just testing that these calls do not raise exceptions.
            saved_winsz = fcntl.ioctl(mfd, termios.TIOCGWINSZ, "\0"*8)
            our_winsz = struct.pack("HHHH",80,25,0,0)
            # test both with a positive and potentially negative ioctl code
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
            fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, saved_winsz)
        finally:
            os.close(mfd)
            os.close(sfd) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:25,代码来源:test_ioctl.py

示例4: _setwinsize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def _setwinsize(fd, rows, cols):
    # Some very old platforms have a bug that causes the value for
    # termios.TIOCSWINSZ to be truncated. There was a hack here to work
    # around this, but it caused problems with newer platforms so has been
    # removed. For details see https://github.com/pexpect/pexpect/issues/39
    TIOCSWINSZ = getattr(termios, 'TIOCSWINSZ', -2146929561)
    # Note, assume ws_xpixel and ws_ypixel are zero.
    s = struct.pack('HHHH', rows, cols, 0, 0)
    fcntl.ioctl(fd, TIOCSWINSZ, s) 
开发者ID:nokia,项目名称:moler,代码行数:11,代码来源:terminal.py

示例5: test_winsize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def test_winsize(many_lines, many_columns):
    """Test height and width is appropriately queried in a pty."""
    @as_subprocess
    def child(lines=25, cols=80):
        # set the pty's virtual window size
        val = struct.pack('HHHH', lines, cols, 0, 0)
        fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)
        term = TestTerminal()
        winsize = term._height_and_width()
        assert term.width == cols
        assert term.height == lines
        assert winsize.ws_col == cols
        assert winsize.ws_row == lines

    child(lines=many_lines, cols=many_columns) 
开发者ID:QData,项目名称:deepWordBug,代码行数:17,代码来源:test_length_sequence.py

示例6: test_Sequence_alignment

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def test_Sequence_alignment(all_terms):
    """Tests methods related to Sequence class, namely ljust, rjust, center."""
    @as_subprocess
    def child(kind, lines=25, cols=80):
        # set the pty's virtual window size
        val = struct.pack('HHHH', lines, cols, 0, 0)
        fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)
        term = TestTerminal(kind=kind)

        pony_msg = 'pony express, all aboard, choo, choo!'
        pony_len = len(pony_msg)
        pony_colored = u''.join(
            ['%s%s' % (term.color(n % 7), ch,)
             for n, ch in enumerate(pony_msg)])
        pony_colored += term.normal
        ladjusted = term.ljust(pony_colored)
        radjusted = term.rjust(pony_colored)
        centered = term.center(pony_colored)
        assert (term.length(pony_colored) == pony_len)
        assert (term.length(centered.strip()) == pony_len)
        assert (term.length(centered) == len(pony_msg.center(term.width)))
        assert (term.length(ladjusted.strip()) == pony_len)
        assert (term.length(ladjusted) == len(pony_msg.ljust(term.width)))
        assert (term.length(radjusted.strip()) == pony_len)
        assert (term.length(radjusted) == len(pony_msg.rjust(term.width)))

    child(kind=all_terms) 
开发者ID:QData,项目名称:deepWordBug,代码行数:29,代码来源:test_length_sequence.py

示例7: proc_keepalive

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def proc_keepalive(self, sid, w, h):
		if not sid in self.session:
			# Start a new session
			self.session[sid] = {
				'state':'unborn',
				'term':	Terminal(w, h),
				'time':	time.time(),
				'w':	w,
				'h':	h}
			return self.proc_spawn(sid)
		elif self.session[sid]['state'] == 'alive':
			self.session[sid]['time'] = time.time()
			# Update terminal size
			if self.session[sid]['w'] != w or self.session[sid]['h'] != h:
				try:
					fcntl.ioctl(fd, 
						struct.unpack('i', 
							struct.pack('I', termios.TIOCSWINSZ)
						)[0],
						struct.pack("HHHH", h, w, 0, 0))
				except (IOError, OSError):
					pass
				self.session[sid]['term'].set_size(w, h)
				self.session[sid]['w'] = w
				self.session[sid]['h'] = h
			return True
		else:
			return False 
开发者ID:xypiie,项目名称:WebShell,代码行数:30,代码来源:webshell.py

示例8: __init__

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def __init__(self):
        stdin = FileDescriptorSTDIN(0)
        stdout = FileDescriptorSTDOUT(1)
        stderr = FileDescriptorSTDERR(2)
        for std in [stdin, stdout, stderr]:
            std.uid = self.user_uid
            std.gid = self.user_gid
        self.file_descriptors = {
            0: stdin,
            1: stdout,
            2: stderr,
        }
        self.ioctl_allowed = [
            (0, termios.TCGETS),
            (0, termios.TIOCGWINSZ),
            (0, termios.TIOCSWINSZ),
            (1, termios.TCGETS),
            (1, termios.TIOCGWINSZ),
            (1, termios.TIOCSWINSZ),
        ]
        self.ioctl_disallowed = [
            (2, termios.TCGETS),
            (0, termios.TCSETSW),
        ]
        self.filesystem = FileSystem(self.filesystem_base, self)
        self.network = Networking(self) 
开发者ID:cea-sec,项目名称:miasm,代码行数:28,代码来源:environment.py

示例9: ioctl

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def ioctl(self, fd, cmd, arg):
        """Stub for 'ioctl' syscall
        Return the list of element to pack back depending on target ioctl
        If the ioctl is disallowed, return False
        """
        allowed = False
        disallowed = False
        for test in [(fd, cmd), (None, cmd), (fd, None)]:
            if test in self.ioctl_allowed:
                allowed = True
            if test in self.ioctl_disallowed:
                disallowed = True

        if allowed and disallowed:
            raise ValueError("fd: %x, cmd: %x is allowed and disallowed" % (fd, cmd))

        if allowed:
            if cmd == termios.TCGETS:
                return 0, 0, 0, 0
            elif cmd == termios.TIOCGWINSZ:
                # struct winsize
                # {
                #   unsigned short ws_row;	/* rows, in characters */
                #   unsigned short ws_col;	/* columns, in characters */
                #   unsigned short ws_xpixel;	/* horizontal size, pixels */
                #   unsigned short ws_ypixel;	/* vertical size, pixels */
                # };
                return 1000, 360, 1000, 1000
            elif cmd == termios.TIOCSWINSZ:
                # Ignore it
                return
            else:
                raise RuntimeError("Not implemented")

        elif disallowed:
            return False

        else:
            raise KeyError("Unknown ioctl fd:%x cmd:%x" % (fd, cmd)) 
开发者ID:cea-sec,项目名称:miasm,代码行数:41,代码来源:environment.py

示例10: resize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def resize(self, rows, cols, em_dimensions=None, ctrl_l=True):
        """
        Resizes the child process's terminal window to *rows* and *cols* by
        first sending it a TIOCSWINSZ event and then sending ctrl-l.

        If *em_dimensions* are provided they will be updated along with the
        rows and cols.

        The sending of ctrl-l can be disabled by setting *ctrl_l* to False.
        """
        logging.debug(
            "Resizing term %s to rows: %s, cols: %s, em_dimensions=%s"
            % (self.term_id, rows, cols, em_dimensions))
        if rows < 2:
            rows = 24
        if cols < 2:
            cols = 80
        self.rows = rows
        self.cols = cols
        self.term.resize(rows, cols, em_dimensions)
        # Sometimes the resize doesn't actually apply (for whatever reason)
        # so to get around this we have to send a different value than the
        # actual value we want then send our actual value.  It's a bug outside
        # of Gate One that I have no idea how to isolate but this has proven to
        # be an effective workaround.
        import fcntl, termios
        s = struct.pack("HHHH", rows, cols, 0, 0)
        try:
            fcntl.ioctl(self.fd, termios.TIOCSWINSZ, s)
        except IOError:
            # Process already ended--no big deal
            return
        try:
            os.kill(self.pid, signal.SIGWINCH) # Send the resize signal
        except OSError:
            return # Process is dead.  Can happen when things go quickly
        if ctrl_l:
            self.write(u'\x0c') # ctrl-l 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:40,代码来源:termio.py

示例11: _set_pty_size

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def _set_pty_size(master_fd):
    buf = array.array('h', [0, 0, 0, 0])
    fcntl.ioctl(pty.STDOUT_FILENO, termios.TIOCGWINSZ, buf, True)
    fcntl.ioctl(master_fd, termios.TIOCSWINSZ, buf) 
开发者ID:nvbn,项目名称:thefuck,代码行数:6,代码来源:shell_logger.py

示例12: resize_pty

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def resize_pty(pty):
    try:
        winsize = struct.pack('HHHH', 0, 0, 0, 0)
        winsize = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, winsize)
        fcntl.ioctl(pty, termios.TIOCSWINSZ, winsize)
    except IOError:
        # Nice to have, but not necessary
        pass 
开发者ID:rpm-software-management,项目名称:mock,代码行数:10,代码来源:util.py

示例13: set_terminal_geometry

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def set_terminal_geometry(file_descriptor: int, rows: int, columns: int) -> None:
    term_geometry_struct = struct.pack("HHHH", rows, columns, 0, 0)
    fcntl.ioctl(
        file_descriptor, termios.TIOCSWINSZ, term_geometry_struct
    ) 
开发者ID:actionless,项目名称:pikaur,代码行数:7,代码来源:pikspect.py

示例14: test_SequenceWrapper

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def test_SequenceWrapper(all_terms, many_columns):
    """Test that text wrapping accounts for sequences correctly."""
    @as_subprocess
    def child(kind, lines=25, cols=80):

        # set the pty's virtual window size
        val = struct.pack('HHHH', lines, cols, 0, 0)
        fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)

        # build a test paragraph, along with a very colorful version
        t = TestTerminal(kind=kind)
        pgraph = u' '.join(
            ('a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefgh',
             'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl',
             'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmno',) * 4)
        pgraph_colored = u''.join([
            t.color(n % 7) + t.bold + ch
            for n, ch in enumerate(pgraph)])

        internal_wrapped = textwrap.wrap(pgraph, t.width,
                                         break_long_words=False)
        my_wrapped = t.wrap(pgraph)
        my_wrapped_colored = t.wrap(pgraph_colored)

        # ensure we textwrap ascii the same as python
        assert (internal_wrapped == my_wrapped)

        # ensure our first and last line wraps at its ends
        first_l = internal_wrapped[0]
        last_l = internal_wrapped[-1]
        my_first_l = my_wrapped_colored[0]
        my_last_l = my_wrapped_colored[-1]
        assert (len(first_l) == t.length(my_first_l))
        assert (len(last_l) == t.length(my_last_l))
        assert (len(internal_wrapped[-1]) == t.length(my_wrapped_colored[-1]))

    child(kind=all_terms, lines=25, cols=many_columns) 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:39,代码来源:test_wrap.py

示例15: test_winsize

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TIOCSWINSZ [as 别名]
def test_winsize(many_lines, many_columns):
    """Test height and width is appropriately queried in a pty."""
    @as_subprocess
    def child(lines=25, cols=80):
        # set the pty's virtual window size
        val = struct.pack('HHHH', lines, cols, 0, 0)
        fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)
        t = TestTerminal()
        winsize = t._height_and_width()
        assert t.width == cols
        assert t.height == lines
        assert winsize.ws_col == cols
        assert winsize.ws_row == lines

    child(lines=many_lines, cols=many_columns) 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:17,代码来源:test_length_sequence.py


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