Python termios.IGNCR Examples
The following are 6
code examples of termios.IGNCR().
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: recipe-580680.py From code with MIT License | 5 votes |
def prepare_tty(): "set the terminal in char mode (return each keyboard press at once) and"\ " switch off echoing of this input; return the original settings" stdin_fd = sys.stdin.fileno() # will most likely be 0 ;-> old_stdin_config = termios.tcgetattr(stdin_fd) [ iflag, oflag, cflag, lflag, ispeed, ospeed, cc ] = \ termios.tcgetattr(stdin_fd) cc[termios.VTIME] = 1 cc[termios.VMIN] = 1 iflag = iflag & ~(termios.IGNBRK | termios.BRKINT | termios.PARMRK | termios.ISTRIP | termios.INLCR | termios.IGNCR | #termios.ICRNL | termios.IXON) # oflag = oflag & ~termios.OPOST cflag = cflag | termios.CS8 lflag = lflag & ~(termios.ECHO | termios.ECHONL | termios.ICANON | # termios.ISIG | termios.IEXTEN) termios.tcsetattr(stdin_fd, termios.TCSANOW, [ iflag, oflag, cflag, lflag, ispeed, ospeed, cc ]) return (stdin_fd, old_stdin_config)
Example #2
Source File: vt100.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _patch_iflag(cls, attrs): return attrs & ~( # Disable XON/XOFF flow control on output and input. # (Don't capture Ctrl-S and Ctrl-Q.) # Like executing: "stty -ixon." termios.IXON | termios.IXOFF | # Don't translate carriage return into newline on input. termios.ICRNL | termios.INLCR | termios.IGNCR )
Example #3
Source File: vt100_input.py From android_universal with MIT License | 5 votes |
def _patch_iflag(cls, attrs): return attrs & ~( # Disable XON/XOFF flow control on output and input. # (Don't capture Ctrl-S and Ctrl-Q.) # Like executing: "stty -ixon." termios.IXON | termios.IXOFF | # Don't translate carriage return into newline on input. termios.ICRNL | termios.INLCR | termios.IGNCR )
Example #4
Source File: Pipe.py From redeem with GNU General Public License v3.0 | 4 votes |
def __init__(self, printer, prot, iomanager): self.printer = printer self.prot = prot self.iomanager = iomanager (master_fd, slave_fd) = os.openpty() slave = os.ttyname(slave_fd) master_flags = fcntl.fcntl(master_fd, fcntl.F_GETFL, 0) fcntl.fcntl(master_fd, fcntl.F_SETFL, master_flags | os.O_NONBLOCK) # switch to "raw" mode - these constants come from the manpage for termios under cfmakeraw() master_attr = termios.tcgetattr(master_fd) master_attr[0] &= ~(termios.IGNBRK | termios.BRKINT | termios.PARMRK | termios.ISTRIP | termios.INLCR | termios.IGNCR | termios.ICRNL | termios.IXON) master_attr[1] &= ~termios.OPOST master_attr[2] &= ~(termios.CSIZE | termios.PARENB) master_attr[3] &= ~(termios.ECHO | termios.ECHONL | termios.ICANON | termios.ISIG | termios.IEXTEN) master_attr[3] |= termios.CS8 termios.tcsetattr(master_fd, termios.TCSADRAIN, master_attr) # Fun detail: master will always show as /dev/ptmx, but the kernel knows from # the fd which PTY we're using. This means we have to use master_fd instead # of opening master by name. logging.info("Opened PTY for {} and got {}".format(prot, os.ttyname(slave_fd))) self.pipe_link = "/dev/" + prot + "_1" try: os.unlink(self.pipe_link) except OSError as e: # file not found is fine to ignore - anythine else and we should log it if e.errno != errno.ENOENT: logging.error("Failed to unlink '{}': {}".format(self.pipe_link, e.strerror)) logging.info("linking {}".format(self.pipe_link)) os.symlink(slave, self.pipe_link) os.chmod(self.pipe_link, 0o666) logging.info("{} Pipe open. Use '{}' to communicate with it".format(self.prot, self.pipe_link)) self.rd = os.fdopen(master_fd, "r") self.wr = os.fdopen(master_fd, "w") self.send_response = True self.iomanager.add_file(self.rd, self.get_message)
Example #5
Source File: misc.py From fast-autocomplete with MIT License | 4 votes |
def read_single_keypress(): """Waits for a single keypress on stdin. https://stackoverflow.com/a/6599441/1497443 This is a silly function to call if you need to do it a lot because it has to store stdin's current setup, setup stdin for reading single keystrokes then read the single keystroke then revert stdin back after reading the keystroke. Returns the character of the key that was pressed (zero on KeyboardInterrupt which can happen when a signal gets handled) """ if fcntl is None or termios is None: raise ValueError('termios and/or fcntl packages are not available in your system. This is possible because you are not on a Linux Distro.') 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 try: ret = sys.stdin.read(1) # returns a single character except KeyboardInterrupt: ret = 0 finally: # restore old state termios.tcsetattr(fd, termios.TCSAFLUSH, attrs_save) fcntl.fcntl(fd, fcntl.F_SETFL, flags_save) return ret
Example #6
Source File: vt100_input.py From android_universal with MIT License | 4 votes |
def feed(self, data): """ Feed the input stream. :param data: Input string (unicode). """ assert isinstance(data, six.text_type) if _DEBUG_RENDERER_INPUT: self.LOG.write(repr(data).encode('utf-8') + b'\n') self.LOG.flush() # Handle bracketed paste. (We bypass the parser that matches all other # key presses and keep reading input until we see the end mark.) # This is much faster then parsing character by character. if self._in_bracketed_paste: self._paste_buffer += data end_mark = '\x1b[201~' if end_mark in self._paste_buffer: end_index = self._paste_buffer.index(end_mark) # Feed content to key bindings. paste_content = self._paste_buffer[:end_index] self.feed_key_callback(KeyPress(Keys.BracketedPaste, paste_content)) # Quit bracketed paste mode and handle remaining input. self._in_bracketed_paste = False remaining = self._paste_buffer[end_index + len(end_mark):] self._paste_buffer = '' self.feed(remaining) # Handle normal input character by character. else: for i, c in enumerate(data): if self._in_bracketed_paste: # Quit loop and process from this position when the parser # entered bracketed paste. self.feed(data[i:]) break else: # Replace \r by \n. (Some clients send \r instead of \n # when enter is pressed. E.g. telnet and some other # terminals.) # XXX: We should remove this in a future version. It *is* # now possible to recognise the difference. # (We remove ICRNL/INLCR/IGNCR below.) # However, this breaks IPython and maybe other applications, # because they bind ControlJ (\n) for handling the Enter key. # When this is removed, replace Enter=ControlJ by # Enter=ControlM in keys.py. if c == '\r': c = '\n' self._input_parser.send(c)