Python tty.setcbreak() Examples
The following are 30
code examples of tty.setcbreak().
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
tty
, or try the search function
.
Example #1
Source File: main.py From kitty with GNU General Public License v3.0 | 7 votes |
def yesno(cli_opts: AskCLIOptions, items: List[str]) -> Response: import tty with alternate_screen(): if cli_opts.message: print(styled(cli_opts.message, bold=True)) print() print(' ', styled('Y', fg='green') + 'es', ' ', styled('N', fg='red') + 'o', set_cursor_visible(False)) sys.stdout.flush() tty.setraw(sys.stdin.fileno()) try: response = sys.stdin.buffer.read(1) yes = response in (b'y', b'Y', b'\r', b'\n' b' ') return {'items': items, 'response': 'y' if yes else 'n'} finally: sys.stdout.write(set_cursor_visible(True)) tty.setcbreak(sys.stdin.fileno()) sys.stdout.flush()
Example #2
Source File: pppd.py From sstp-server with MIT License | 6 votes |
def main(): #setcbreak(stdin, TCSANOW) stdin = sys.stdin.buffer stdout = sys.stdout.buffer stdout.write(LCP1_EN + LCP1_EN[1:]) stdout.flush() assert stdin.read(len(LCP1_EN)) == LCP1_EN assert stdin.read(len(LCP1_EN)) == LCP1_EN time.sleep(0.2) # waiting for auth ok stdout.write(IP1_EN) stdout.flush() assert stdin.read(len(IP1_EN)) == IP1_EN stdout.write(IP1_EN) stdout.flush() time.sleep(0.2)
Example #3
Source File: pydoc.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #4
Source File: pydoc.py From jawfish with MIT License | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = plain(text).split('\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write('\n'.join(lines[:inc]) + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + '\n'.join(lines[r:r+inc]) + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #5
Source File: pydoc.py From medicare-demo with Apache License 2.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #6
Source File: __init__.py From isf with BSD 2-Clause "Simplified" License | 5 votes |
def posix_shell(chan): import termios import tty oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) chan.settimeout(0.0) while True: r, w, e = select.select([chan, sys.stdin], [], []) if chan in r: try: x = unicode(chan.recv(1024)) if len(x) == 0: break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break chan.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) return
Example #7
Source File: keypress.py From term2048-AI with MIT License | 5 votes |
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 #8
Source File: pydoc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #9
Source File: pydoc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #10
Source File: keypress.py From term2048 with MIT License | 5 votes |
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 #11
Source File: fungsi.py From txtool with GNU General Public License v2.0 | 5 votes |
def ssh_shell(command): from paramiko.py3compat import u oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) command.settimeout(0.0) while True: r, w, e = select.select([command, sys.stdin], [], []) if command in r: try: x = u(command.recv(1024)) if len(x) == 0: sys.stdout.write('\r\n{0}[x]{1} shell closed'.format(warna.merah, warna.tutup)) break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break command.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
Example #12
Source File: raw_display.py From anyMesh-Python with MIT License | 5 votes |
def start(self, alternate_buffer=True): """ Initialize the screen and input mode. alternate_buffer -- use alternate screen buffer """ assert not self._started if alternate_buffer: self._term_output_file.write(escape.SWITCH_TO_ALTERNATE_BUFFER) self._rows_used = None else: self._rows_used = 0 fd = self._term_input_file.fileno() if os.isatty(fd): self._old_termios_settings = termios.tcgetattr(fd) tty.setcbreak(fd) self.signal_init() self._alternate_buffer = alternate_buffer self._input_iter = self._run_input_iter() self._next_timeout = self.max_wait if not self._signal_keys_set: self._old_signal_keys = self.tty_signal_keys(fileno=fd) super(Screen, self).start() signals.emit_signal(self, INPUT_DESCRIPTORS_CHANGED) # restore mouse tracking to previous state self._mouse_tracking(self._mouse_tracking_enabled)
Example #13
Source File: mp.py From mpwn with MIT License | 5 votes |
def tty_interact(fd: int=0) -> Iterator[None]: old_settings = termios.tcgetattr(fd) try: tty.setcbreak(fd) yield except KeyboardInterrupt: pass finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
Example #14
Source File: mypydoc.py From azure-linux-extensions with Apache License 2.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #15
Source File: interactive.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def posix_shell(chan): import select oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) chan.settimeout(0.0) while True: r, w, e = select.select([chan, sys.stdin], [], []) if chan in r: try: x = chan.recv(1024) if len(x) == 0: print '\r\n*** EOF\r\n', break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break chan.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) # thanks to Mike Looijmans for this code
Example #16
Source File: pydoc.py From canape with GNU General Public License v3.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #17
Source File: pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #18
Source File: pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #19
Source File: interactive.py From python-hpedockerplugin with Apache License 2.0 | 5 votes |
def posix_shell(chan): import select oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) chan.settimeout(0.0) while True: r, w, e = select.select([chan, sys.stdin], [], []) if chan in r: try: x = u(chan.recv(1024)) if len(x) == 0: sys.stdout.write('\r\n*** EOF\r\n') break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break chan.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) # thanks to Mike Looijmans for this code
Example #20
Source File: utilities.py From aurman with MIT License | 5 votes |
def ask_user(question: str, default: bool, new_line: bool = False) -> bool: """ Asks the user a yes/no question. :param question: The question to ask :param default: The default answer, if user presses enter. True for yes, False for no :param new_line: If new_line before printing the question :return: yes: True, no: False """ yes = ["y"] no = ["n"] if default: yes.append("") choices = "Y/n" else: no.append("") choices = "N/y" while True: print(aurman_question("{} {}: ".format(question, choices), new_line=new_line, to_print=False), end='', flush=True) # see https://stackoverflow.com/a/36974338 fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setcbreak(fd) answer = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) print(flush=True) user_choice = answer.strip().lower() if user_choice in yes or user_choice in no: return user_choice in yes aurman_error("That was not a valid choice!")
Example #21
Source File: pydoc.py From meddle with MIT License | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #22
Source File: pydoc.py From BinderFilter with MIT License | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #23
Source File: pydoc.py From Computable with MIT License | 5 votes |
def ttypager(text): """Page through text on a text terminal.""" lines = split(plain(text), '\n') try: import tty fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd) getchar = lambda: sys.stdin.read(1) except (ImportError, AttributeError): tty = None getchar = lambda: sys.stdin.readline()[:-1][:1] try: r = inc = os.environ.get('LINES', 25) - 1 sys.stdout.write(join(lines[:inc], '\n') + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() c = getchar() if c in ('q', 'Q'): sys.stdout.write('\r \r') break elif c in ('\r', '\n'): sys.stdout.write('\r \r' + lines[r] + '\n') r = r + 1 continue if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') r = r + inc finally: if tty: tty.tcsetattr(fd, tty.TCSAFLUSH, old)
Example #24
Source File: text.py From encompass with GNU General Public License v3.0 | 5 votes |
def main(self,url): tty.setraw(sys.stdin) while self.tab != -1: self.run_tab(0, self.print_history, self.run_history_tab) self.run_tab(1, self.print_send_tab, self.run_send_tab) self.run_tab(2, self.print_receive, self.run_receive_tab) self.run_tab(3, self.print_contacts, self.run_contacts_tab) self.run_tab(4, self.print_banner, self.run_banner_tab) tty.setcbreak(sys.stdin) curses.nocbreak() self.stdscr.keypad(0) curses.echo() curses.endwin()
Example #25
Source File: __init__.py From Industrial-Security-Auditing-Framework with GNU General Public License v3.0 | 5 votes |
def posix_shell(chan): import termios import tty oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) chan.settimeout(0.0) while True: r, w, e = select.select([chan, sys.stdin], [], []) if chan in r: try: x = chan.recv(1024).decode("UTF-8") if len(x) == 0: break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break chan.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) return
Example #26
Source File: interactive.py From aws-extender with MIT License | 5 votes |
def posix_shell(chan): import select oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) chan.settimeout(0.0) while True: r, w, e = select.select([chan, sys.stdin], [], []) if chan in r: try: x = chan.recv(1024) if len(x) == 0: print('\r\n*** EOF\r\n', end=' ') break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break chan.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) # thanks to Mike Looijmans for this code
Example #27
Source File: helpers.py From decrypt-ios-apps-script with MIT License | 5 votes |
def interactive_shell(chan, callback=None): oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) chan.settimeout(0.0) while True: r, w, e = select.select([chan, sys.stdin], [], []) if chan in r: try: x = u(chan.recv(1024)) if len(x) == 0: sys.stdout.write("\r\n[+] Terminating SSH connection\r\n") sys.stdout.flush() if callback != None: callback() break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break chan.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
Example #28
Source File: pikspect.py From pikaur with GNU General Public License v3.0 | 5 votes |
def __enter__(self) -> os.terminal_size: real_term_geometry = shutil.get_terminal_size((80, 80)) if sys.stdin.isatty(): tty.setcbreak(sys.stdin.fileno()) if sys.stderr.isatty(): tty.setcbreak(sys.stderr.fileno()) if sys.stdout.isatty(): tty.setcbreak(sys.stdout.fileno()) return real_term_geometry
Example #29
Source File: failover_console.py From mysql-utilities with GNU General Public License v2.0 | 5 votes |
def _wait_for_interval(self): """Wait for the time interval to expire This method issues a timing loop to wait for the specified interval to expire or quit if the user presses 'q' or 'Q'. The method passes all other keyboard requests to the _do_command() method for processing. If the interval expires, the method returns None. If the user presses a key, the method returns the numeric key number. Returns - None or int (see above) """ # If on *nix systems, set the terminal IO sys to not echo if not self.no_keyboard and os.name == "posix": import tty import termios old_settings = termios.tcgetattr(sys.stdin) tty.setcbreak(sys.stdin.fileno()) key = None done = False try: # Loop for interval in seconds while detecting keypress while not done: done = self.alarm <= time.time() if not self.no_keyboard and kbhit() and not done: key = getch() done = True if os.name != "posix": # On Windows wait a few ms to avoid 100% CPU usage for # polling input (handled in kbhit() for posix systems). time.sleep(_IDLE_TIME_INPUT_POLLING) finally: # Ensure terminal IO sys is reset to older state. if not self.no_keyboard and os.name == "posix": termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) return key
Example #30
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