From 0d2afa302b19d3bd19c43841d30d1fff4e58648f Mon Sep 17 00:00:00 2001 From: Stefan Nickl Date: Tue, 5 Jul 2016 15:48:35 +0200 Subject: [PATCH] Single key operation getch() implementation based on https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user https://github.com/joeyespo/py-getch/blob/master/getch/getch.py --- codemod/base.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/codemod/base.py b/codemod/base.py index 8479290..6e55caa 100755 --- a/codemod/base.py +++ b/codemod/base.py @@ -686,6 +686,20 @@ def _ask_about_patch(patch, editor, default_no): if p in 'eE': run_editor(patch.start_position, editor) +try: + from msvcrt import getch +except ImportError: + import tty + import termios + def getch(): + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + + try: + tty.setraw(fd) + return sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) def _prompt(letters='yn', default=None): """ @@ -696,7 +710,7 @@ def _prompt(letters='yn', default=None): """ while True: try: - input_text = sys.stdin.readline().strip() + input_text = getch() except KeyboardInterrupt: sys.exit(0) if input_text and input_text in letters: