Skip to content

Commit 195e296

Browse files
committed
Handle non-interactive stdin in migration keypress pause
1 parent 49135e6 commit 195e296

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/mcpm/migration/v1_migrator.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ def _wait_for_keypress(self, message: str):
4444
tty = None
4545

4646
console.print(message, end="")
47+
console.file.flush()
48+
49+
if not sys.stdin.isatty():
50+
console.print()
51+
return
52+
53+
def _fallback_wait():
54+
try:
55+
input()
56+
except (EOFError, OSError):
57+
pass
4758

4859
if termios and tty:
4960
try:
@@ -55,17 +66,17 @@ def _wait_for_keypress(self, message: str):
5566
sys.stdin.read(1)
5667
finally:
5768
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
58-
except (AttributeError, termios.error, ValueError, OSError):
59-
input()
69+
except (AttributeError, termios.error, ValueError, OSError, EOFError):
70+
_fallback_wait()
6071
else:
6172
try:
6273
import msvcrt
6374
try:
6475
msvcrt.getch()
65-
except OSError:
66-
input()
76+
except (OSError, EOFError):
77+
_fallback_wait()
6778
except ImportError:
68-
input()
79+
_fallback_wait()
6980

7081
console.print() # Add newline after keypress
7182

0 commit comments

Comments
 (0)