Python termios.TCSAFLUSH Examples
The following are 30
code examples of termios.TCSAFLUSH().
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: wizardofoz.py From saywizard with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: failover_console.py From mysql-utilities with GNU General Public License v2.0 | 6 votes |
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
Example #3
Source File: console.py From mysql-utilities with GNU General Public License v2.0 | 6 votes |
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
Example #4
Source File: kleinanzeigen.py From ebayKleinanzeigen with Apache License 2.0 | 6 votes |
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
Example #5
Source File: keypress.py From faceswap with GNU General Public License v3.0 | 6 votes |
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)
Example #6
Source File: utils.py From fandogh-cli with MIT License | 6 votes |
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)
Example #7
Source File: terminal.py From ashier with Apache License 2.0 | 6 votes |
def SetTerminalRaw(fd, restore=False): """Set controlling terminal to raw mode. Set controlling terminal to raw mode and, if requested, register an exit handler to restore controlling terminal attribute on exit. Args: fd: file descriptor of the controlling terminal. restore: whether terminal mode should be restored on exit Returns: None. """ if restore: when = termios.TCSAFLUSH orig_attr = termios.tcgetattr(fd) atexit.register(lambda: termios.tcsetattr(fd, when, orig_attr)) tty.setraw(fd)
Example #8
Source File: keyboard_hit.py From RocketCEA with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: TerminalProcess.py From deprecated-binaryninja-python with GNU General Public License v2.0 | 5 votes |
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()
Example #10
Source File: terminal.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
def cbreak(self): """Return a context manager that enters 'cbreak' mode: disabling line buffering of keyboard input, making characters typed by the user immediately available to the program. Also referred to as 'rare' mode, this is the opposite of 'cooked' mode, the default for most shells. In 'cbreak' mode, echo of input is also disabled: the application must explicitly print any input received, if they so wish. More information can be found in the manual page for curses.h, http://www.openbsd.org/cgi-bin/man.cgi?query=cbreak The python manual for curses, http://docs.python.org/2/library/curses.html Note also that setcbreak sets VMIN = 1 and VTIME = 0, http://www.unixwiz.net/techtips/termios-vmin-vtime.html """ if self.keyboard_fd is not None: # save current terminal mode, save_mode = termios.tcgetattr(self.keyboard_fd) tty.setcbreak(self.keyboard_fd, termios.TCSANOW) try: yield finally: # restore prior mode, termios.tcsetattr(self.keyboard_fd, termios.TCSAFLUSH, save_mode) else: yield
Example #11
Source File: keypress.py From faceswap with GNU General Public License v3.0 | 5 votes |
def set_normal_term(self): """ Resets to normal terminal. On Windows this is a no-op. """ if os.name == "nt" or self.is_gui: pass else: termios.tcsetattr(self.file_desc, termios.TCSAFLUSH, self.old_term)
Example #12
Source File: randpool.py From python-for-android with Apache License 2.0 | 5 votes |
def close(self, delay = 0): if delay: time.sleep(delay) termios.tcflush(self._fd, termios.TCIFLUSH) termios.tcsetattr(self._fd, termios.TCSAFLUSH, self._old)
Example #13
Source File: randpool.py From python-for-android with Apache License 2.0 | 5 votes |
def close(self, delay = 0): if delay: time.sleep(delay) termios.tcflush(self._fd, termios.TCIFLUSH) termios.tcsetattr(self._fd, termios.TCSAFLUSH, self._old)
Example #14
Source File: randpool.py From python-for-android with Apache License 2.0 | 5 votes |
def close(self, delay = 0): if delay: time.sleep(delay) termios.tcflush(self._fd, termios.TCIFLUSH) termios.tcsetattr(self._fd, termios.TCSAFLUSH, self._old)
Example #15
Source File: terminalkeyboard.py From bard with GNU General Public License v3.0 | 5 votes |
def read_key(): 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) oldstdinfl = fcntl.fcntl(1, fcntl.F_GETFL) try: seq = '' while characters_left_for_sequence(seq): if len(seq) > 0: fcntl.fcntl(1, fcntl.F_SETFL, oldstdinfl | os.O_NONBLOCK) ch = sys.stdin.read(1) if not ch: break seq += ch except IOError: pass finally: termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) fcntl.fcntl(1, fcntl.F_SETFL, oldstdinfl) try: result = TerminalKeyDict[seq] except KeyError: result = seq return result
Example #16
Source File: epdb_client.py From conary with Apache License 2.0 | 5 votes |
def restore_terminal(self): fd = sys.stdin.fileno() if self.oldTerm: termios.tcsetattr(fd, termios.TCSAFLUSH, self.oldTerm) if self.oldFlags: fcntl.fcntl(fd, fcntl.F_SETFL, self.oldFlags)
Example #17
Source File: parent.py From mitogen with BSD 3-Clause "New" or "Revised" License | 5 votes |
def disable_echo(fd): old = termios.tcgetattr(fd) new = cfmakeraw(old) flags = getattr(termios, 'TCSASOFT', 0) if not mitogen.core.IS_WSL: # issue #319: Windows Subsystem for Linux as of July 2018 throws EINVAL # if TCSAFLUSH is specified. flags |= termios.TCSAFLUSH termios.tcsetattr(fd, flags, new)
Example #18
Source File: epdb_client.py From epdb with MIT License | 5 votes |
def restore_terminal(self): fd = sys.stdin.fileno() if self.oldTerm: termios.tcsetattr(fd, termios.TCSAFLUSH, self.oldTerm) if self.oldFlags: fcntl.fcntl(fd, fcntl.F_SETFL, self.oldFlags)
Example #19
Source File: AirSimClient.py From AirGym with MIT License | 5 votes |
def wait_key(message = ''): ''' Wait for a key press on the console and return it. ''' if message != '': print (message) 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
Example #20
Source File: miniterm.py From android_universal with MIT License | 5 votes |
def cleanup(self): termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
Example #21
Source File: input_kbd.py From DeepPicar-v2 with GNU General Public License v2.0 | 5 votes |
def stop(state): fd = sys.stdin.fileno() # restore old state termios.tcsetattr(fd, termios.TCSAFLUSH, state[1]) fcntl.fcntl(fd, fcntl.F_SETFL, state[0])
Example #22
Source File: keyboard.py From crazyswarm with MIT License | 5 votes |
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
Example #23
Source File: keyboard.py From crazyswarm with MIT License | 5 votes |
def __exit__(self, type, value, traceback): termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
Example #24
Source File: keyboard_hit.py From RocketCEA with GNU General Public License v3.0 | 5 votes |
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)
Example #25
Source File: serial_terminal.py From pros-cli2 with Mozilla Public License 2.0 | 5 votes |
def cleanup(self): termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
Example #26
Source File: miniterm.py From ddt4all with GNU General Public License v3.0 | 5 votes |
def cleanup(self): termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
Example #27
Source File: Wanem.py From EM-uNetPi with MIT License | 5 votes |
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)
Example #28
Source File: keyboard.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(raw_args): parser = argparse.ArgumentParser( description="Use your keyboard as your phone's keyboard.") logging_common.AddLoggingArguments(parser) script_common.AddDeviceArguments(parser) args = parser.parse_args(raw_args) logging_common.InitializeLogging(args) devices = script_common.GetDevices(args.devices, None) if len(devices) > 1: raise MultipleDevicesError(devices) def next_char(): while True: yield sys.stdin.read(1) try: fd = sys.stdin.fileno() # See man 3 termios for more info on what this is doing. old_attrs = termios.tcgetattr(fd) new_attrs = copy.deepcopy(old_attrs) new_attrs[tty.LFLAG] = new_attrs[tty.LFLAG] & ~(termios.ICANON) new_attrs[tty.CC][tty.VMIN] = 1 new_attrs[tty.CC][tty.VTIME] = 0 termios.tcsetattr(fd, termios.TCSAFLUSH, new_attrs) Keyboard(devices[0], next_char()) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old_attrs) return 0
Example #29
Source File: miniterm.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
def cleanup(self): if self.old is not None: termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
Example #30
Source File: keyboard.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(raw_args): parser = argparse.ArgumentParser( description="Use your keyboard as your phone's keyboard.") logging_common.AddLoggingArguments(parser) script_common.AddDeviceArguments(parser) args = parser.parse_args(raw_args) logging_common.InitializeLogging(args) devices = script_common.GetDevices(args.devices, None) if len(devices) > 1: raise MultipleDevicesError(devices) def next_char(): while True: yield sys.stdin.read(1) try: fd = sys.stdin.fileno() # See man 3 termios for more info on what this is doing. old_attrs = termios.tcgetattr(fd) new_attrs = copy.deepcopy(old_attrs) new_attrs[tty.LFLAG] = new_attrs[tty.LFLAG] & ~(termios.ICANON) new_attrs[tty.CC][tty.VMIN] = 1 new_attrs[tty.CC][tty.VTIME] = 0 termios.tcsetattr(fd, termios.TCSAFLUSH, new_attrs) Keyboard(devices[0], next_char()) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old_attrs) return 0