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


Python tty.setcbreak方法代码示例

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


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

示例1: yesno

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def yesno(cli_opts: AskCLIOptions, items: List[str]) -> Response:
    import tty
    with alternate_screen():
        if cli_opts.message:
            print(styled(cli_opts.message, bold=True))
        print()
        print(' ', styled('Y', fg='green') + 'es', ' ', styled('N', fg='red') + 'o', set_cursor_visible(False))
        sys.stdout.flush()
        tty.setraw(sys.stdin.fileno())
        try:
            response = sys.stdin.buffer.read(1)
            yes = response in (b'y', b'Y', b'\r', b'\n' b' ')
            return {'items': items, 'response': 'y' if yes else 'n'}
        finally:
            sys.stdout.write(set_cursor_visible(True))
            tty.setcbreak(sys.stdin.fileno())
            sys.stdout.flush() 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:19,代码来源:main.py

示例2: main

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def main():
    #setcbreak(stdin, TCSANOW)
    stdin = sys.stdin.buffer
    stdout = sys.stdout.buffer

    stdout.write(LCP1_EN + LCP1_EN[1:])
    stdout.flush()
    assert stdin.read(len(LCP1_EN)) == LCP1_EN
    assert stdin.read(len(LCP1_EN)) == LCP1_EN

    time.sleep(0.2)  # waiting for auth ok

    stdout.write(IP1_EN)
    stdout.flush()
    assert stdin.read(len(IP1_EN)) == IP1_EN
    stdout.write(IP1_EN)
    stdout.flush()

    time.sleep(0.2) 
开发者ID:sorz,项目名称:sstp-server,代码行数:21,代码来源:pppd.py

示例3: ttypager

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def ttypager(text):
    """Page through text on a text terminal."""
    lines = plain(text).split('\n')
    try:
        import tty
        fd = sys.stdin.fileno()
        old = tty.tcgetattr(fd)
        tty.setcbreak(fd)
        getchar = lambda: sys.stdin.read(1)
    except (ImportError, AttributeError):
        tty = None
        getchar = lambda: sys.stdin.readline()[:-1][:1]

    try:
        r = inc = os.environ.get('LINES', 25) - 1
        sys.stdout.write('\n'.join(lines[:inc]) + '\n')
        while lines[r:]:
            sys.stdout.write('-- more --')
            sys.stdout.flush()
            c = getchar()

            if c in ('q', 'Q'):
                sys.stdout.write('\r          \r')
                break
            elif c in ('\r', '\n'):
                sys.stdout.write('\r          \r' + lines[r] + '\n')
                r = r + 1
                continue
            if c in ('b', 'B', '\x1b'):
                r = r - inc - inc
                if r < 0: r = 0
            sys.stdout.write('\n' + '\n'.join(lines[r:r+inc]) + '\n')
            r = r + inc

    finally:
        if tty:
            tty.tcsetattr(fd, tty.TCSAFLUSH, old) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:39,代码来源:pydoc.py

示例4: ttypager

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def ttypager(text):
    """Page through text on a text terminal."""
    lines = split(plain(text), '\n')
    try:
        import tty
        fd = sys.stdin.fileno()
        old = tty.tcgetattr(fd)
        tty.setcbreak(fd)
        getchar = lambda: sys.stdin.read(1)
    except (ImportError, AttributeError):
        tty = None
        getchar = lambda: sys.stdin.readline()[:-1][:1]

    try:
        r = inc = os.environ.get('LINES', 25) - 1
        sys.stdout.write(join(lines[:inc], '\n') + '\n')
        while lines[r:]:
            sys.stdout.write('-- more --')
            sys.stdout.flush()
            c = getchar()

            if c in ('q', 'Q'):
                sys.stdout.write('\r          \r')
                break
            elif c in ('\r', '\n'):
                sys.stdout.write('\r          \r' + lines[r] + '\n')
                r = r + 1
                continue
            if c in ('b', 'B', '\x1b'):
                r = r - inc - inc
                if r < 0: r = 0
            sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n')
            r = r + inc

    finally:
        if tty:
            tty.tcsetattr(fd, tty.TCSAFLUSH, old) 
开发者ID:glmcdona,项目名称:meddle,代码行数:39,代码来源:pydoc.py

示例5: main

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def main(self,url):

        tty.setraw(sys.stdin)
        while self.tab != -1:
            self.run_tab(0, self.print_history, self.run_history_tab)
            self.run_tab(1, self.print_send_tab, self.run_send_tab)
            self.run_tab(2, self.print_receive, self.run_receive_tab)
            self.run_tab(3, self.print_contacts, self.run_contacts_tab)
            self.run_tab(4, self.print_banner, self.run_banner_tab)

        tty.setcbreak(sys.stdin)
        curses.nocbreak()
        self.stdscr.keypad(0)
        curses.echo()
        curses.endwin() 
开发者ID:mazaclub,项目名称:encompass,代码行数:17,代码来源:text.py

示例6: posix_shell

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def posix_shell(chan):
    import termios
    import tty

    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = chan.recv(1024).decode("UTF-8")
                    if len(x) == 0:
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass

            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)
    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
        return 
开发者ID:d0ubl3g,项目名称:Industrial-Security-Auditing-Framework,代码行数:32,代码来源:__init__.py

示例7: ask_user

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def ask_user(question: str, default: bool, new_line: bool = False) -> bool:
    """
    Asks the user a yes/no question.
    :param question:    The question to ask
    :param default:     The default answer, if user presses enter.
                        True for yes, False for no
    :param new_line:    If new_line before printing the question
    :return:            yes: True, no: False
    """

    yes = ["y"]
    no = ["n"]
    if default:
        yes.append("")
        choices = "Y/n"
    else:
        no.append("")
        choices = "N/y"

    while True:
        print(aurman_question("{} {}: ".format(question, choices), new_line=new_line, to_print=False),
              end='', flush=True)

        # see https://stackoverflow.com/a/36974338
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)

        try:
            tty.setcbreak(fd)
            answer = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)

        print(flush=True)
        user_choice = answer.strip().lower()
        if user_choice in yes or user_choice in no:
            return user_choice in yes
        aurman_error("That was not a valid choice!") 
开发者ID:polygamma,项目名称:aurman,代码行数:40,代码来源:utilities.py

示例8: interactive_shell

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def interactive_shell(chan, callback=None):
    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = u(chan.recv(1024))
                    if len(x) == 0:
                        sys.stdout.write("\r\n[+] Terminating SSH connection\r\n")
                        sys.stdout.flush()
                        if callback != None:
                            callback()
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass
            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)

    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) 
开发者ID:ivRodriguezCA,项目名称:decrypt-ios-apps-script,代码行数:32,代码来源:helpers.py

示例9: __enter__

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def __enter__(self) -> os.terminal_size:
        real_term_geometry = shutil.get_terminal_size((80, 80))
        if sys.stdin.isatty():
            tty.setcbreak(sys.stdin.fileno())
            if sys.stderr.isatty():
                tty.setcbreak(sys.stderr.fileno())
            if sys.stdout.isatty():
                tty.setcbreak(sys.stdout.fileno())
        return real_term_geometry 
开发者ID:actionless,项目名称:pikaur,代码行数:11,代码来源:pikspect.py

示例10: _wait_for_interval

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def _wait_for_interval(self):
        """Wait for the time interval to expire

        This method issues a timing loop to wait for the specified interval to
        expire or quit if the user presses 'q' or 'Q'. The method passes all
        other keyboard requests to the _do_command() method for processing.

        If the interval expires, the method returns None.
        If the user presses a key, the method returns the numeric key number.

        Returns - None or int (see above)
        """
        # If on *nix systems, set the terminal IO sys to not echo
        if not self.no_keyboard and os.name == "posix":
            import tty
            import termios
            old_settings = termios.tcgetattr(sys.stdin)
            tty.setcbreak(sys.stdin.fileno())

        key = None
        done = False
        try:
            # Loop for interval in seconds while detecting keypress
            while not done:
                done = self.alarm <= time.time()
                if not self.no_keyboard and kbhit() and not done:
                    key = getch()
                    done = True
                if os.name != "posix":
                    # On Windows wait a few ms to avoid 100% CPU usage for
                    # polling input (handled in kbhit() for posix systems).
                    time.sleep(_IDLE_TIME_INPUT_POLLING)
        finally:
            # Ensure terminal IO sys is reset to older state.
            if not self.no_keyboard and os.name == "posix":
                termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)

        return key 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:40,代码来源:failover_console.py

示例11: cbreak

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def cbreak(self):
        """Return a context manager that enters 'cbreak' mode: disabling line
        buffering of keyboard input, making characters typed by the user
        immediately available to the program.  Also referred to as 'rare'
        mode, this is the opposite of 'cooked' mode, the default for most
        shells.

        In 'cbreak' mode, echo of input is also disabled: the application must
        explicitly print any input received, if they so wish.

        More information can be found in the manual page for curses.h,
        http://www.openbsd.org/cgi-bin/man.cgi?query=cbreak

        The python manual for curses,
        http://docs.python.org/2/library/curses.html

        Note also that setcbreak sets VMIN = 1 and VTIME = 0,
        http://www.unixwiz.net/techtips/termios-vmin-vtime.html
        """
        if self.keyboard_fd is not None:
            # save current terminal mode,
            save_mode = termios.tcgetattr(self.keyboard_fd)
            tty.setcbreak(self.keyboard_fd, termios.TCSANOW)
            try:
                yield
            finally:
                # restore prior mode,
                termios.tcsetattr(self.keyboard_fd,
                                  termios.TCSAFLUSH,
                                  save_mode)
        else:
            yield 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:34,代码来源:terminal.py

示例12: test_cbreak_no_kb

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def test_cbreak_no_kb():
    "cbreak() should not call tty.setcbreak() without keyboard."
    @as_subprocess
    def child():
        with tempfile.NamedTemporaryFile() as stream:
            term = TestTerminal(stream=stream)
            with mock.patch("tty.setcbreak") as mock_setcbreak:
                with term.cbreak():
                    assert not mock_setcbreak.called
    child() 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:12,代码来源:test_keyboard.py

示例13: posix_shell

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def posix_shell(chan):
    import select
    
    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = chan.recv(1024)
                    if len(x) == 0:
                        print('\r\n*** EOF\r\n', end=' ')
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass
            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)

    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)

    
# thanks to Mike Looijmans for this code 
开发者ID:VirtueSecurity,项目名称:aws-extender,代码行数:34,代码来源:interactive.py

示例14: start

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def start(self, alternate_buffer=True):
        """
        Initialize the screen and input mode.

        alternate_buffer -- use alternate screen buffer
        """
        assert not self._started
        if alternate_buffer:
            self._term_output_file.write(escape.SWITCH_TO_ALTERNATE_BUFFER)
            self._rows_used = None
        else:
            self._rows_used = 0

        fd = self._term_input_file.fileno()
        if os.isatty(fd):
            self._old_termios_settings = termios.tcgetattr(fd)
            tty.setcbreak(fd)

        self.signal_init()
        self._alternate_buffer = alternate_buffer
        self._input_iter = self._run_input_iter()
        self._next_timeout = self.max_wait

        if not self._signal_keys_set:
            self._old_signal_keys = self.tty_signal_keys(fileno=fd)

        super(Screen, self).start()

        signals.emit_signal(self, INPUT_DESCRIPTORS_CHANGED)
        # restore mouse tracking to previous state
        self._mouse_tracking(self._mouse_tracking_enabled) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:33,代码来源:raw_display.py

示例15: posix_shell

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setcbreak [as 别名]
def posix_shell(chan):
    import termios
    import tty

    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = unicode(chan.recv(1024))
                    if len(x) == 0:
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass

            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)
    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
        return 
开发者ID:dark-lbp,项目名称:isf,代码行数:32,代码来源:__init__.py


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