base.py 文件源码

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

项目:runcommands 作者: wylee 项目源码 文件源码
def unbuffer_stdin(self, stdin):
        """Make ``stdin`` char buffered instead of line buffered.

        Return a function that resets ``stdin`` to its previous buffer
        settings. This is intended to be used with try/finally like so::

        reset_stdin = self.unbuffer_stdin(sys.stdin)
        try:
            # do stuff with unbuffered stdin
        finally:
            reset_stdin()

        .. note:: This was taken from Fabric's ``char_buffered`` context
                  manager and tweaked slightly to work with try/finally.

        """
        if not isatty(stdin):
            return lambda: None

        original_term_settings = termios.tcgetattr(stdin)
        tty.setcbreak(stdin)

        def reset():
            termios.tcsetattr(stdin, termios.TCSADRAIN, original_term_settings)

        return reset
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号