terminal_input.py 文件源码

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

项目:goreviewpartner 作者: pnprog 项目源码 文件源码
def stop_was_requested(self):
        """Check whether a 'keyboard stop' instruction has been sent.

        Returns true if ^X has been sent on the controlling terminal.

        Consumes all available input on /dev/tty.

        """
        if not self.enabled:
            return False
        # Don't try to read the terminal if we're in the background.
        # There's a race here, if we're backgrounded just after this check, but
        # I don't see a clean way to avoid it.
        if os.tcgetpgrp(self.tty.fileno()) != os.getpid():
            return False
        try:
            termios.tcsetattr(self.tty, termios.TCSANOW, self.cbreak_tcattr)
        except EnvironmentError:
            return False
        try:
            seen_ctrl_x = False
            while True:
                c = os.read(self.tty.fileno(), 1)
                if not c:
                    break
                if c == "\x18":
                    seen_ctrl_x = True
        except EnvironmentError:
            seen_ctrl_x = False
        finally:
            termios.tcsetattr(self.tty, termios.TCSANOW, self.clean_tcattr)
        return seen_ctrl_x
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号