Python termios.TCIOFLUSH Examples

The following are 6 code examples of termios.TCIOFLUSH(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module termios , or try the search function .
Example #1
Source File: ipc.py    From hupper with MIT License 5 votes vote down vote up
def restore_termios(stream, state):
        if state and is_stream_interactive(stream):
            fd = stream.fileno()
            termios.tcflush(fd, termios.TCIOFLUSH)
            termios.tcsetattr(fd, termios.TCSANOW, state) 
Example #2
Source File: pikspect.py    From pikaur with GNU General Public License v3.0 5 votes vote down vote up
def _restore(cls, what: Optional[TcAttrsType] = None) -> None:
        if sys.stdout.isatty():
            # termios.tcdrain(sys.stdout.fileno())
            # if sys.stderr.isatty():
            #     termios.tcdrain(sys.stderr.fileno())
            # if sys.stdin.isatty():
            #     termios.tcflush(sys.stdin.fileno(), termios.TCIOFLUSH)
            if what:
                termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, what) 
Example #3
Source File: main_daemon.py    From Pythonic with GNU General Public License v3.0 5 votes vote down vote up
def run(self):

        if self.b_init:
            self.b_init = False
            self.fd = sys.stdin.fileno() 
            if os.isatty(sys.stdin.fileno()):
                self.old_settings = termios.tcgetattr(self.fd) 
                tty.setraw(sys.stdin.fileno()) 

        while not self.b_exit:

            rd_fs, wrt_fs, err_fs =  select.select([sys.stdin], [], [], self.interval)

            if rd_fs and os.isatty(sys.stdin.fileno()):
                cmd = rd_fs[0].read(1)

                if cmd == ('q' or 'Q'): # quit
                    termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)
                    termios.tcflush(self.fd, termios.TCIOFLUSH)
                    self.b_exit = True
                    self.quit_app.emit()

                elif cmd == ('p' or 'P'): # show proccesses
                    self.b_procs = True
                    termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)
                    self.print_procs.emit()
                    tty.setraw(sys.stdin.fileno()) 

                elif cmd == ('l' or 'L'): # show log
                    if self.b_log:
                        termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)
                        reset_screen() # reset the screen to hide the log list
                        tty.setraw(sys.stdin.fileno()) 
                    self.b_log = not self.b_log
                    
                else:
                    sys.stdout.write('\b')

            else:
                if os.isatty(sys.stdin.fileno()):
                    self.callback() 
Example #4
Source File: keypress.py    From term2048-AI with MIT License 5 votes vote down vote up
def __getKey():
        """Return a key pressed by the user"""
        try:
            tty.setcbreak(sys.stdin.fileno())
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            ch = sys.stdin.read(1)
            return ord(ch) if ch else None
        finally:
            termios.tcsetattr(__fd, termios.TCSADRAIN, __old) 
Example #5
Source File: keypress.py    From term2048 with MIT License 5 votes vote down vote up
def __getKey():
        """Return a key pressed by the user"""
        try:
            tty.setcbreak(sys.stdin.fileno())
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            ch = sys.stdin.read(1)
            return ord(ch) if ch else None
        finally:
            termios.tcsetattr(__fd, termios.TCSADRAIN, __old) 
Example #6
Source File: g1modules.py    From gluster-one with GNU General Public License v3.0 4 votes vote down vote up
def user_input(msg, initial=''):
    # Function to capture raw_input w/ key buffer flush
    tcflush(sys.stdin, TCIOFLUSH)
    readline.set_startup_hook(lambda: readline.insert_text(initial))
    keyin = raw_input(msg)
    return keyin