Python termios 模块,TCSAFLUSH 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用termios.TCSAFLUSH

项目:speech_ml    作者:coopie    | 项目源码 | 文件源码
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)
项目:saywizard    作者:bensauer    | 项目源码 | 文件源码
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
项目:miros    作者:aleph2c    | 项目源码 | 文件源码
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)
项目:led    作者:rec    | 项目源码 | 文件源码
def keyboard(callback, exit='q'):
    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:
        while True:
            try:
                ch = sys.stdin.read(1)
                if ch:
                    callback(ch)
                    if ch == exit:
                        break
            except IOError:
                pass
    finally:
        termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
项目:Halite    作者:shummie    | 项目源码 | 文件源码
def __enter__(self):
        # 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)     

        # switch to unbuffered terminal
        termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)

        return self.query_keyboard
项目:pwndemo    作者:zh-explorer    | 项目源码 | 文件源码
def setupterm():
    global settings
    update_geometry()
    hide_cursor()
    do('smkx') # keypad mode
    if not settings:
        settings = termios.tcgetattr(fd.fileno())
    mode = termios.tcgetattr(fd.fileno())
    IFLAG = 0
    OFLAG = 1
    CFLAG = 2
    LFLAG = 3
    ISPEED = 4
    OSPEED = 5
    CC = 6
    mode[LFLAG] = mode[LFLAG] & ~(termios.ECHO | termios.ICANON | termios.IEXTEN)
    mode[CC][termios.VMIN] = 1
    mode[CC][termios.VTIME] = 0
    termios.tcsetattr(fd, termios.TCSAFLUSH, mode)
项目:vrptw-pgss-2016    作者:conwayje    | 项目源码 | 文件源码
def __enter__(self):
        global isWindows
        if isWindows:
            self.readHandle = GetStdHandle(STD_INPUT_HANDLE)
            self.readHandle.SetConsoleMode(ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT)

            self.curEventLength = 0
            self.curKeysLength = 0

            self.capturedChars = []
        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)

        return self
项目:overhead_mobile_tracker    作者:NU-MSR    | 项目源码 | 文件源码
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)
项目:RobotControl    作者:vdwel    | 项目源码 | 文件源码
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)
项目:unitils    作者:iLoveTux    | 项目源码 | 文件源码
def get_keypress():
        """Wait for a keypress and return key pressed. This is
        the *nix version of this command"""
        import termios, fcntl, sys, os
        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:
            while 1:
                try:
                    c = sys.stdin.read(1)
                    break
                except IOError: pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
        return c
项目:piglass    作者:matt-desmarais    | 项目源码 | 文件源码
def getch():
    fd = sys.stdin.fileno()     
    oldattr = 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:
        while True:
            try:
                c = sys.stdin.read(1)
            except IOError:
                pass
            else:
                return c
    finally:
        termios.tcsetattr(fd, termios.TCSAFLUSH, oldattr)
        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
项目:kimhun_rl_windows    作者:nalsil    | 项目源码 | 文件源码
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)
项目:black_zone    作者:zh-explorer    | 项目源码 | 文件源码
def setupterm():
    global settings
    update_geometry()
    hide_cursor()
    do('smkx') # keypad mode
    if not settings:
        settings = termios.tcgetattr(fd.fileno())
    mode = termios.tcgetattr(fd.fileno())
    IFLAG = 0
    OFLAG = 1
    CFLAG = 2
    LFLAG = 3
    ISPEED = 4
    OSPEED = 5
    CC = 6
    mode[LFLAG] = mode[LFLAG] & ~(termios.ECHO | termios.ICANON | termios.IEXTEN)
    mode[CC][termios.VMIN] = 1
    mode[CC][termios.VTIME] = 0
    termios.tcsetattr(fd, termios.TCSAFLUSH, mode)
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def set_normal_term():
    termios.tcsetattr(fd, termios.TCSAFLUSH, old_term)

# switch to unbuffered terminal
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def set_curses_term():
    termios.tcsetattr(fd, termios.TCSAFLUSH, new_term)
项目:android3dblendermouse    作者:sketchpunk    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:miros    作者:aleph2c    | 项目源码 | 文件源码
def set_normal_term(self):
        ''' Resets to normal terminal.  On Windows this is a no-op.
        '''

        if os.name == 'nt':
            pass

        else:
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def restart(self, cmd):
        if not self.completed:
            self.process_input("\n\033[01;31mProcess killed.\033[00m\r\n")
            os.kill(self.pid, signal.SIGHUP)
            thread = self.thread
            thread.stop()
            while thread.alive:
                QCoreApplication.processEvents()

        self.exit_pipe, child_pipe = os.pipe()
        pid, fd = pty.fork()
        if pid == 0:
            try:
                os.environ["TERM"] = "xterm-256color"
                retval = subprocess.call(cmd, close_fds=True)
                os.write(2, "\033[01;34mProcess has completed.\033[00m\n")
                os.write(child_pipe, "t")
                os._exit(retval)
            except:
                pass
            os.write(2, "\033[01;31mCommand '" + cmd[0] + "' failed to execute.\033[00m\n")
            os.write(child_pipe, "f")
            os._exit(1)

        os.close(child_pipe)
        self.process_input("\033[01;34mStarted process with PID %d.\033[00m\r\n" % pid)

        self.pid = pid
        self.data_pipe = fd
        self.completed = False

        # Initialize terminal settings
        fcntl.ioctl(self.data_pipe, termios.TIOCSWINSZ, struct.pack("hhhh", self.rows, self.cols, 0, 0))
        attribute = termios.tcgetattr(self.data_pipe)
        termios.tcsetattr(self.data_pipe, termios.TCSAFLUSH, attribute)

        self.thread = TerminalUpdateThread(self, self.data_pipe, self.exit_pipe)
        self.thread.start()
项目:microperi    作者:c0d3st0rm    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:mitogen    作者:dw    | 项目源码 | 文件源码
def disable_echo(fd):
    old = termios.tcgetattr(fd)
    new = cfmakeraw(old)
    flags = (
        termios.TCSAFLUSH |
        getattr(termios, 'TCSASOFT', 0)
    )
    termios.tcsetattr(fd, flags, new)
项目:microbit-gateway    作者:whaleygeek    | 项目源码 | 文件源码
def cleanup(self):
            if self.old is not None:
                termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:mb_remote    作者:whaleygeek    | 项目源码 | 文件源码
def cleanup(self):
            if self.old is not None:
                termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:gcodeplot    作者:arpruss    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:gcodeplot    作者:arpruss    | 项目源码 | 文件源码
def cleanup(self):
            if self.old is not None:
                termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:bitio    作者:whaleygeek    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:crazyswarm    作者:USC-ACTLab    | 项目源码 | 文件源码
def __enter__(self):
        # 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)

        return self
项目:crazyswarm    作者:USC-ACTLab    | 项目源码 | 文件源码
def __exit__(self, type, value, traceback):
        termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:microbit-serial    作者:martinohanlon    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:FrozenBottle    作者:freieslabor    | 项目源码 | 文件源码
def __init__(self):
        global CIO_STARTED
        if CIO_STARTED:
            raise Exception("cannot init cio twice")
        CIO_STARTED = True
        self.buf=''
        self.fh_ocfg=list()
        if os.name == 'posix':
            # for posix, need to set to non-canonical input.
            self.posix=True
            fh = sys.stdin.fileno()
            # if the following call fails, we are probably called with a stdin which is not a tty.
            ocfg = termios.tcgetattr(fh)
            cfg = termios.tcgetattr(fh)
            cfg[3] = cfg[3]&~termios.ICANON&~termios.ECHO
            #cfg[0] = cfg[0]&~termios.INLCR
            #cfg[1] = cfg[0]&~termios.OCRNL
            cfg[6][termios.VMIN] = 0
            cfg[6][termios.VTIME] = 0
            termios.tcsetattr(fh,termios.TCSAFLUSH,cfg)
            self.fh_ocfg.extend((fh,ocfg))
            atexit.register(stop_canon_input,self.fh_ocfg)
        elif os.name == 'nt':
            # for windows, don't need to configure the terminal.
            self.posix=False
        else:
            # know only posix and windows...
            raise Exception("os variant %s not supported"%repr(os.name))
项目:FrozenBottle    作者:freieslabor    | 项目源码 | 文件源码
def stop_canon_input(fh_ocfg):
    if fh_ocfg is None:
        return
    args = fh_ocfg[:]
    del fh_ocfg[:]
    if len(args)>=2:
        termios.tcsetattr(args[0],termios.TCSAFLUSH,args[1])



# some tiny test program if started as standalone.
项目:driveboardapp    作者:nortd    | 项目源码 | 文件源码
def cleanup(self):
            if self.old is not None:
                termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:Halite    作者:shummie    | 项目源码 | 文件源码
def __exit__(self, type, value, traceback):
        # swith to normal terminal
        termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:bootrom-tools    作者:MotorolaMobilityLLC    | 项目源码 | 文件源码
def run(self):
        if os.name != "posix":
            raise ValueError("Can only be run on Posix systems")
            return

        buffer = ""
        # While PySerial would be preferable and more machine-independant,
        # it does not support echo suppression
        with open(self.dbgser_tty_name, 'r+') as dbgser:
            # Config the debug serial port
            oldattrs = termios.tcgetattr(dbgser)
            newattrs = termios.tcgetattr(dbgser)
            newattrs[4] = termios.B115200  # ispeed
            newattrs[5] = termios.B115200  # ospeed
            newattrs[3] = newattrs[3] & ~termios.ICANON & ~termios.ECHO
            newattrs[6][termios.VMIN] = 0
            newattrs[6][termios.VTIME] = 10
            termios.tcsetattr(dbgser, termios.TCSANOW, newattrs)

            # As long as we weren't asked to stop, try to capture dbgserial
            # output and push each line up the result queue.
            try:
                while not self.stoprequest.isSet():
                    ch = dbgser.read(1)
                    if ch:
                        if ch == "\n":
                            # Push the line (sans newline) into our queue
                            # and clear the buffer for the next line.
                            self.result_q.put(buffer)
                            buffer = ""
                        elif ch != "\r":
                            buffer += ch
            except IOError:
                pass
            finally:
                # Restore previous settings
                termios.tcsetattr(dbgser, termios.TCSAFLUSH, oldattrs)
                # Flush any partial buffer
                if buffer:
                    self.result_q.put(buffer)
项目:vrptw-pgss-2016    作者:conwayje    | 项目源码 | 文件源码
def __exit__(self, type, value, traceback):
        if isWindows:
            pass
        else:
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:overhead_mobile_tracker    作者:NU-MSR    | 项目源码 | 文件源码
def set_normal_term(self):
        ''' Resets to normal terminal.  On Windows this is a no-op.
        '''

        if os.name == 'nt':
            pass

        else:
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:mb_sdcard    作者:whaleygeek    | 项目源码 | 文件源码
def cleanup(self):
            if self.old is not None:
                termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:ddt4all    作者:cedricp    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:RobotControl    作者:vdwel    | 项目源码 | 文件源码
def set_normal_term(self):
        ''' Resets to normal terminal.  On Windows this is a no-op.
        '''

        if os.name == 'nt':
            pass

        else:
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:HaliteBot    作者:jheilema-nerdery    | 项目源码 | 文件源码
def __enter__(self):
        # 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)     

        # switch to unbuffered terminal
        termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)

        return self.query_keyboard
项目:HaliteBot    作者:jheilema-nerdery    | 项目源码 | 文件源码
def __exit__(self, type, value, traceback):
        # swith to normal terminal
        termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:speech_ml    作者:coopie    | 项目源码 | 文件源码
def set_normal_term(self):
        ''' Resets to normal terminal.  On Windows this is a no-op.
        '''
        if os.name == 'nt':
            pass
        else:
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:mt7687-serial-uploader    作者:will127534    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:get_started_with_respeaker    作者:respeaker    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:5minute    作者:SatelliteQE    | 项目源码 | 文件源码
def warning(message, answer=None):
    """
    Print warning message into srdErr and may can for answer
    :param message: message
    :param answer: list of supported options. Default is first item.
    """
    c = ""
    if sys.stderr.isatty():
        sys.stderr.write("\n\x1b[92;01m%s " % message)
    else:
        sys.stderr.write("\n%s " % message)
    if answer:
        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:
            while 1:
                try:
                    c = sys.stdin.read(1)
                    break
                except IOError:
                    pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
        c = ("%s" % c).lower()
    if sys.stderr.isatty():
        sys.stderr.write(" %s\x1b[39;49;00m\n\n" % c)
    else:
        sys.stderr.write(" %s\n\n" % c)
    if answer:
        for it in answer:
            if c in it:
                return c
        return answer.pop(0)
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:kimhun_rl_windows    作者:nalsil    | 项目源码 | 文件源码
def set_normal_term(self):
        ''' Resets to normal terminal.  On Windows this is a no-op.
        '''

        if os.name == 'nt':
            pass

        else:
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
项目:btc-fpga-miner    作者:marsohod4you    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
项目:btc-fpga-miner    作者:marsohod4you    | 项目源码 | 文件源码
def cleanup(self):
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)