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


Python tty.setraw方法代码示例

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


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

示例1: raw_terminal

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def raw_terminal():
        if not isatty(sys.stdin):
            f = open('/dev/tty')
            fd = f.fileno()
        else:
            fd = sys.stdin.fileno()
            f = None
        try:
            old_settings = termios.tcgetattr(fd)
            try:
                tty.setraw(fd)
                yield fd
            finally:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
                sys.stdout.flush()
                if f is not None:
                    f.close()
        except termios.error:
            pass 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:_termui_impl.py

示例2: getchar

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def getchar(echo):
        if not isatty(sys.stdin):
            f = open('/dev/tty')
            fd = f.fileno()
        else:
            fd = sys.stdin.fileno()
            f = None
        try:
            old_settings = termios.tcgetattr(fd)
            try:
                tty.setraw(fd)
                ch = os.read(fd, 32)
                if echo and isatty(sys.stdout):
                    sys.stdout.write(ch)
            finally:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
                sys.stdout.flush()
                if f is not None:
                    f.close()
        except termios.error:
            pass
        _translate_ch_to_exc(ch)
        return ch.decode(get_best_encoding(sys.stdin), 'replace') 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:_termui_impl.py

示例3: read_char_no_blocking

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def read_char_no_blocking():
    ''' Read a character in nonblocking mode, if no characters are present in the buffer, return an empty string '''
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    old_flags = fcntl.fcntl(fd, fcntl.F_GETFL)
    try:
        tty.setraw(fd, termios.TCSADRAIN)
        fcntl.fcntl(fd, fcntl.F_SETFL, old_flags | os.O_NONBLOCK)
        return sys.stdin.read(1)
    except IOError as e:
        ErrorNumber = e[0]
        # IOError with ErrorNumber 11(35 in Mac)  is thrown when there is nothing to read(Resource temporarily unavailable)
        if (sys.platform.startswith("linux") and ErrorNumber != 11) or (sys.platform == "darwin" and ErrorNumber != 35):
            raise
        return ""
    finally:
        fcntl.fcntl(fd, fcntl.F_SETFL, old_flags)
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 
开发者ID:pindexis,项目名称:marker,代码行数:20,代码来源:readchar.py

示例4: spawn

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def spawn(argv, master_read=_read, stdin_read=_read):
    """Create a spawned process."""
    if type(argv) == type(''):
        argv = (argv,)
    pid, master_fd = fork()
    if pid == CHILD:
        os.execlp(argv[0], *argv)
    try:
        mode = tty.tcgetattr(STDIN_FILENO)
        tty.setraw(STDIN_FILENO)
        restore = 1
    except tty.error:    # This is the same as termios.error
        restore = 0
    try:
        _copy(master_fd, master_read, stdin_read)
    except (IOError, OSError):
        if restore:
            tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)

    os.close(master_fd) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:pty.py

示例5: raw_terminal

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def raw_terminal():
        if not isatty(sys.stdin):
            f = open("/dev/tty")
            fd = f.fileno()
        else:
            fd = sys.stdin.fileno()
            f = None
        try:
            old_settings = termios.tcgetattr(fd)
            try:
                tty.setraw(fd)
                yield fd
            finally:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
                sys.stdout.flush()
                if f is not None:
                    f.close()
        except termios.error:
            pass 
开发者ID:pypa,项目名称:pipenv,代码行数:21,代码来源:_termui_impl.py

示例6: __call__

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def __call__(self):
        import sys, tty, termios
        from select import select

        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)

        try:
            tty.setraw(sys.stdin.fileno())

            # [ Wait until ready for reading,
            #   wait until ready for writing
            #   wait for an "exception condition" ]
            # The below line times out after 1 second
            # This can be changed to a floating-point value if necessary
            [i, o, e] = select([sys.stdin.fileno()], [], [], 1)
            if i:
                ch = sys.stdin.read(1)
            else:
                ch = None

        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)

        return ch 
开发者ID:AlexisTM,项目名称:flyingros,代码行数:27,代码来源:getch.py

示例7: spawn

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def spawn(argv, master_read=_read, stdin_read=_read):
    """Create a spawned process."""
    if type(argv) == type(''):
        argv = (argv,)
    pid, master_fd = fork()
    if pid == CHILD:
        os.execlp(argv[0], *argv)
    try:
        mode = tty.tcgetattr(STDIN_FILENO)
        tty.setraw(STDIN_FILENO)
        restore = 1
    except tty.error:    # This is the same as termios.error
        restore = 0
    try:
        _copy(master_fd, master_read, stdin_read)
    except OSError:
        if restore:
            tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)

    os.close(master_fd)
    return os.waitpid(pid, 0)[1] 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:pty.py

示例8: yesno

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [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

示例9: __call__

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch 
开发者ID:EarToEarOak,项目名称:RF-Monitor,代码行数:12,代码来源:utils_cli.py

示例10: getchar

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def getchar():
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:11,代码来源:logtest.py

示例11: _find_getch

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def _find_getch():
    try:
        import termios
    except ImportError:
        # Non-POSIX. Return msvcrt's (Windows') getch.
        import msvcrt
        return msvcrt.getch

    # POSIX system. Create and return a getch that manipulates the tty.
    import sys, tty
    def _getch():
        fd = sys.stdin.fileno()
        old_settings = None
        try:
            old_settings = termios.tcgetattr(fd)
            tty.setraw(fd)
        except termios.error:
            pass
        try:
            ch = sys.stdin.read(1)
        finally:
            if old_settings is not None:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

    return _getch 
开发者ID:aaronjanse,项目名称:asciidots,代码行数:28,代码来源:getchar.py

示例12: read_ch

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def read_ch():
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch 
开发者ID:simonmonk,项目名称:raspberrypi_cookbook_ed2,代码行数:11,代码来源:keys_sys.py

示例13: readchar

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def readchar():
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    if ch == '0x03':
        raise KeyboardInterrupt
    return ch 
开发者ID:simonmonk,项目名称:raspberrypi_cookbook_ed2,代码行数:13,代码来源:rover.py

示例14: __call__

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
            sys.stdin.flush()
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch 
开发者ID:Pinafore,项目名称:qb,代码行数:13,代码来源:buzzer.py

示例15: set_terminal

# 需要导入模块: import tty [as 别名]
# 或者: from tty import setraw [as 别名]
def set_terminal():
        """
        Set the terminal to raw state.

        """
        tty.setraw(sys.stdin.fileno()) 
开发者ID:OTL,项目名称:cozmo_driver,代码行数:8,代码来源:teleop_key.py


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