Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Single key operation #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion codemod/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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:
Expand Down