當前位置: 首頁>>代碼示例>>Python>>正文


Python termios.TCSADRAIN屬性代碼示例

本文整理匯總了Python中termios.TCSADRAIN屬性的典型用法代碼示例。如果您正苦於以下問題:Python termios.TCSADRAIN屬性的具體用法?Python termios.TCSADRAIN怎麽用?Python termios.TCSADRAIN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在termios的用法示例。


在下文中一共展示了termios.TCSADRAIN屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: raw_terminal

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [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 termios [as 別名]
# 或者: from termios import TCSADRAIN [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 termios [as 別名]
# 或者: from termios import TCSADRAIN [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: restore_echo

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [as 別名]
def restore_echo():
    """Hack for https://stackoverflow.com/questions/6488275 equivalent
    issue with Nmap (from
    http://stackoverflow.com/a/8758047/3223422)

    """
    try:
        fdesc = sys.stdin.fileno()
    except ValueError:
        return
    try:
        attrs = termios.tcgetattr(fdesc)
    except termios.error:
        return
    attrs[3] = attrs[3] | termios.ECHO
    termios.tcsetattr(fdesc, termios.TCSADRAIN, attrs) 
開發者ID:cea-sec,項目名稱:ivre,代碼行數:18,代碼來源:runscans.py

示例5: __init__

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [as 別名]
def __init__(self, verbosity, maxJobs):
        super().__init__(verbosity)
        self.__index = 1
        self.__maxJobs = maxJobs
        self.__jobs = {}
        self.__slots = [None] * maxJobs
        self.__tasksDone = 0
        self.__tasksNum = 1

        # disable cursor
        print("\x1b[?25l")

        # disable echo
        try:
            import termios
            fd = sys.stdin.fileno()
            self.__oldTcAttr = termios.tcgetattr(fd)
            new = termios.tcgetattr(fd)
            new[3] = new[3] & ~termios.ECHO
            termios.tcsetattr(fd, termios.TCSADRAIN, new)
        except ImportError:
            pass 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:24,代碼來源:tty.py

示例6: raw_terminal

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [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

示例7: __call__

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [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

示例8: getch

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [as 別名]
def getch(prompt=None):
    """Reads a single character from stdin.

    Args:
        prompt (optional): prompt that is presented to user.

    Returns:
        The single character that was read.
    """
    if prompt:
        sys.stdout.write(prompt)

    sys.stdout.flush()

    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:bbugyi200,項目名稱:funky,代碼行數:24,代碼來源:__init__.py

示例9: __call__

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [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 termios [as 別名]
# 或者: from termios import TCSADRAIN [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: make_terminal_unbuffered

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [as 別名]
def make_terminal_unbuffered():
    # Based on https://stackoverflow.com/questions/21791621/taking-input-from-sys-stdin-non-blocking
    # pylint:disable=global-statement
    global OLD_TERMINAL_SETTINGS
    OLD_TERMINAL_SETTINGS = termios.tcgetattr(sys.stdin)
    new_settings = termios.tcgetattr(sys.stdin)
    new_settings[3] = new_settings[3] & ~(termios.ECHO | termios.ICANON)
    new_settings[6][termios.VMIN] = 0
    new_settings[6][termios.VTIME] = 0
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, new_settings) 
開發者ID:brunorijsman,項目名稱:rift-python,代碼行數:12,代碼來源:engine.py

示例12: restore_terminal

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [as 別名]
def restore_terminal():
    # pylint:disable=global-statement
    global OLD_TERMINAL_SETTINGS
    if OLD_TERMINAL_SETTINGS:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, OLD_TERMINAL_SETTINGS)
        OLD_TERMINAL_SETTINGS = None 
開發者ID:brunorijsman,項目名稱:rift-python,代碼行數:8,代碼來源:engine.py

示例13: _find_getch

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [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

示例14: read_ch

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [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

示例15: readchar

# 需要導入模塊: import termios [as 別名]
# 或者: from termios import TCSADRAIN [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


注:本文中的termios.TCSADRAIN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。