Skip to content

Commit e03b096

Browse files
committed
Reintroduced termios check (reverted by mistake from my last commit)
1 parent 0acd2e0 commit e03b096

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

bridge/packet.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@
2525
##
2626
## Copyright 2013 Arduino LLC (http://www.arduino.cc/)
2727

28-
import tty, termios, select
28+
import os, tty, termios, select
2929
from contextlib import contextmanager
3030
from sys import stdin, stdout
3131
from subprocess import call
3232

3333
@contextmanager
3434
def cbreak():
35-
old_attrs = termios.tcgetattr(stdin)
36-
tty.setcbreak(stdin)
37-
tty.setraw(stdin)
35+
if hasattr(stdin, "fileno") and os.isatty(stdin.fileno()):
36+
old_attrs = termios.tcgetattr(stdin)
37+
tty.setcbreak(stdin)
38+
tty.setraw(stdin)
3839
try:
3940
yield
4041
finally:
41-
termios.tcsetattr(stdin, termios.TCSADRAIN, old_attrs)
42+
if hasattr(stdin, "fileno") and os.isatty(stdin.fileno()):
43+
termios.tcsetattr(stdin, termios.TCSADRAIN, old_attrs)
4244

4345
class CRC:
4446
def __init__(self, file):

0 commit comments

Comments
 (0)