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


Python termios.ICANON属性代码示例

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


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

示例1: init

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def init():
    if os.name == 'posix':
        global old
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0

        # -- Cambiar los atributos
        termios.tcsetattr(fd, termios.TCSANOW, new)

        # -- Restaurar el terminal a la salida
        atexit.register(cleanup_console)
    pass


# -------------------------------------
# Pequena prueba del modulo
# ------------------------------------- 
开发者ID:Obijuan,项目名称:simplez-fpga,代码行数:22,代码来源:consola_io.py

示例2: __init__

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def __init__(self):
        '''Creates a KBHit object that you can call to do various keyboard things.
        '''

        if os.name == 'nt':
            pass
        
        else:
    
            # Save the terminal settings
            self.fd = sys.stdin.fileno()
            self.new_term = termios.tcgetattr(self.fd)
            self.old_term = termios.tcgetattr(self.fd)
    
            # New terminal setting unbuffered
            self.new_term[3] = (self.new_term[3] & ~termios.ICANON & ~termios.ECHO)
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)
    
            # Support normal-terminal reset at exit
            atexit.register(self.set_normal_term) 
开发者ID:sonofeft,项目名称:RocketCEA,代码行数:22,代码来源:keyboard_hit.py

示例3: __init__

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def __init__(self):
        '''Creates a KBHit object that you can call to do various keyboard things.
        '''

        if os.name == 'nt':
            pass

        else:

            # Save the terminal settings
            self.fd = sys.stdin.fileno()
            self.new_term = termios.tcgetattr(self.fd)
            self.old_term = termios.tcgetattr(self.fd)

            # New terminal setting unbuffered
            self.new_term[3] = (self.new_term[3] & ~termios.ICANON & ~termios.ECHO)
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)

            # Support normal-terminal reset at exit
            atexit.register(self.set_normal_term) 
开发者ID:fandoghpaas,项目名称:fandogh-cli,代码行数:22,代码来源:utils.py

示例4: wait_key

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def wait_key():
    """ Wait for a key press on the console and return it. """
    result = None
    if os.name == 'nt':
        result = input("Press Enter to continue...")
    else:
        import termios
        fd = sys.stdin.fileno()

        oldterm = termios.tcgetattr(fd)
        newattr = termios.tcgetattr(fd)
        newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
        termios.tcsetattr(fd, termios.TCSANOW, newattr)

        try:
            result = sys.stdin.read(1)
        except IOError:
            pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)

    return result 
开发者ID:donwayo,项目名称:ebayKleinanzeigen,代码行数:24,代码来源:kleinanzeigen.py

示例5: initialise

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def initialise(self):
        if not self.enabled:
            return
        if termios is None:
            self.enabled = False
            return
        try:
            self.tty = open("/dev/tty", "w+")
            os.tcgetpgrp(self.tty.fileno())
            self.clean_tcattr = termios.tcgetattr(self.tty)
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = self.clean_tcattr
            new_lflag = lflag & (0xffffffff ^ termios.ICANON)
            new_cc = cc[:]
            new_cc[termios.VMIN] = 0
            self.cbreak_tcattr = [
                iflag, oflag, cflag, new_lflag, ispeed, ospeed, new_cc]
        except Exception:
            self.enabled = False
            return 
开发者ID:pnprog,项目名称:goreviewpartner,代码行数:21,代码来源:terminal_input.py

示例6: getch

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def getch():
        """getch function
        """
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        termios.tcsetattr(fd, termios.TCSANOW, new)
        key = None
        try:
            key = os.read(fd, 80)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
        return key 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:18,代码来源:console.py

示例7: getch

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def getch():
        """Make a get character keyboard method for Posix machines.
        """
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        termios.tcsetattr(fd, termios.TCSANOW, new)
        key = None
        try:
            key = os.read(fd, 4)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
        return key 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:18,代码来源:failover_console.py

示例8: wait_key

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def wait_key():
    ''' Wait for a key press on the console and return it. '''
    result = None
    if os.name == 'nt':
        import msvcrt
        result = msvcrt.getch()
    else:
        import termios
        fd = sys.stdin.fileno()

        oldterm = termios.tcgetattr(fd)
        newattr = termios.tcgetattr(fd)
        newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
        termios.tcsetattr(fd, termios.TCSANOW, newattr)

        try:
            result = sys.stdin.read(1)
        except IOError:
            pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)

    return result 
开发者ID:bensauer,项目名称:saywizard,代码行数:25,代码来源:wizardofoz.py

示例9: __init__

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def __init__(self, is_gui=False):
        self.is_gui = is_gui
        if os.name == "nt" or self.is_gui:
            pass
        else:
            # Save the terminal settings
            self.file_desc = sys.stdin.fileno()
            self.new_term = termios.tcgetattr(self.file_desc)
            self.old_term = termios.tcgetattr(self.file_desc)

            # New terminal setting unbuffered
            self.new_term[3] = (self.new_term[3] & ~termios.ICANON & ~termios.ECHO)
            termios.tcsetattr(self.file_desc, termios.TCSAFLUSH, self.new_term)

            # Support normal-terminal reset at exit
            atexit.register(self.set_normal_term) 
开发者ID:deepfakes,项目名称:faceswap,代码行数:18,代码来源:keypress.py

示例10: _set_raw_mode_stdin

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def _set_raw_mode_stdin():
  fno = sys.stdin.fileno()
  attr_old = termios.tcgetattr(fno)
  fcntl_old = fcntl.fcntl(fno, fcntl.F_GETFL)

  attr_new = termios.tcgetattr(fno)
  attr_new[3] = attr_new[3] & ~termios.ECHO & ~termios.ICANON
  termios.tcsetattr(fno, termios.TCSADRAIN, attr_new)

  fcntl.fcntl(fno, fcntl.F_SETFL, fcntl_old | os.O_NONBLOCK)

  def reset_raw_mode():
    termios.tcsetattr(fno, termios.TCSANOW, attr_old)
    fcntl.fcntl(fno, fcntl.F_SETFL, fcntl_old)

  return reset_raw_mode 
开发者ID:google,项目名称:mozc-devices,代码行数:18,代码来源:keyboard_recorder.py

示例11: init

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def init():
    fd = sys.stdin.fileno()
    # save old state
    flags_save = fcntl.fcntl(fd, fcntl.F_GETFL)
    attrs_save = termios.tcgetattr(fd)
    # make raw - the way to do this comes from the termios(3) man page.
    attrs = list(attrs_save) # copy the stored version to update
    # iflag
    attrs[0] &= ~(termios.IGNBRK | termios.BRKINT | termios.PARMRK 
                  | termios.ISTRIP | termios.INLCR | termios. IGNCR 
                  | termios.ICRNL | termios.IXON )
    # oflag
    attrs[1] &= ~termios.OPOST
    # cflag
    attrs[2] &= ~(termios.CSIZE | termios. PARENB)
    attrs[2] |= termios.CS8
    # lflag
    attrs[3] &= ~(termios.ECHONL | termios.ECHO | termios.ICANON
                  | termios.ISIG | termios.IEXTEN)
    termios.tcsetattr(fd, termios.TCSANOW, attrs)
    # turn off non-blocking
    fcntl.fcntl(fd, fcntl.F_SETFL, flags_save & ~os.O_NONBLOCK)
    # read a single keystroke
    return (flags_save, attrs_save) 
开发者ID:mbechtel2,项目名称:DeepPicar-v2,代码行数:26,代码来源:input_kbd.py

示例12: make_terminal_unbuffered

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

示例13: sendeof

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def sendeof(self):

        """This sends an EOF to the child. This sends a character which causes
        the pending parent output buffer to be sent to the waiting child
        program without waiting for end-of-line. If it is the first character
        of the line, the read() in the user program returns 0, which signifies
        end-of-file. This means to work as expected a sendeof() has to be
        called at the beginning of a line. This method does not send a newline.
        It is the responsibility of the caller to ensure the eof is sent at the
        beginning of a line. """

        ### Hmmm... how do I send an EOF?
        ###C  if ((m = write(pty, *buf, p - *buf)) < 0)
        ###C      return (errno == EWOULDBLOCK) ? n : -1;
        #fd = sys.stdin.fileno()
        #old = termios.tcgetattr(fd) # remember current state
        #attr = termios.tcgetattr(fd)
        #attr[3] = attr[3] | termios.ICANON # ICANON must be set to recognize EOF
        #try: # use try/finally to ensure state gets restored
        #    termios.tcsetattr(fd, termios.TCSADRAIN, attr)
        #    if hasattr(termios, 'CEOF'):
        #        os.write (self.child_fd, '%c' % termios.CEOF)
        #    else:
        #        # Silly platform does not define CEOF so assume CTRL-D
        #        os.write (self.child_fd, '%c' % 4)
        #finally: # restore state
        #    termios.tcsetattr(fd, termios.TCSADRAIN, old)
        if hasattr(termios, 'VEOF'):
            char = termios.tcgetattr(self.child_fd)[6][termios.VEOF]
        else:
            # platform does not define VEOF so assume CTRL-D
            char = chr(4)
        self.send(char) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:35,代码来源:_pexpect.py

示例14: setup

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def setup(self):
            new = termios.tcgetattr(self.fd)
            new[3] = new[3] & ~termios.ICANON & ~termios.ECHO & ~termios.ISIG
            new[6][termios.VMIN] = 1
            new[6][termios.VTIME] = 0
            termios.tcsetattr(self.fd, termios.TCSANOW, new) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:8,代码来源:miniterm.py

示例15: pause

# 需要导入模块: import termios [as 别名]
# 或者: from termios import ICANON [as 别名]
def pause(secs):
    fd = sys.stdin.fileno()

    oldterm = termios.tcgetattr(fd)
    newattr = termios.tcgetattr(fd)
    newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
    termios.tcsetattr(fd, termios.TCSANOW, newattr)

    oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)

    try:
        ctrlc = False
        paused = False
        t = secs / 0.1
        i = 0
        while i < t:
            if keypressed():
                paused = True
                break
            sleep(0.1)
            i += 1

        if paused:
            while True:
                if keypressed():
                    break
                sleep(0.1)
    except KeyboardInterrupt:
        ctrlc = True

    termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
    if ctrlc:
        sys.exit(1) 
开发者ID:KONAMI,项目名称:EM-uNetPi,代码行数:37,代码来源:Wanem.py


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