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: