Skip to content

Commit 4cdfca7

Browse files
committed
Fix stdin/stdout not being a tty when run from a GTK panel by abstracting out run_stdin and overwriting it in gtk_
1 parent 5b4c2c0 commit 4cdfca7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

bpython/args.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ def parse(args, extras=None):
8888
raise SystemExit
8989

9090
if not (sys.stdin.isatty() and sys.stdout.isatty()):
91-
interpreter = code.InteractiveInterpreter()
92-
interpreter.runsource(sys.stdin.read())
93-
raise SystemExit
94-
91+
run_stdin(sys.stdin)
9592
path = os.path.expanduser('~/.bpythonrc')
9693
# migrating old configuration file
9794
if os.path.isfile(path):
@@ -113,3 +110,11 @@ def exec_code(interpreter, args):
113110
sys.path.insert(0, os.path.abspath(os.path.dirname(args[0])))
114111
interpreter.runcode(code_obj)
115112
sys.argv = old_argv
113+
114+
def run_stdin(stdin):
115+
"""
116+
Run code from a file-like object and exit.
117+
"""
118+
interpreter = code.InteractiveInterpreter()
119+
interpreter.runsource(stdin.read())
120+
raise SystemExit

bpython/gtk_.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
_COLORS = dict(b='blue', c='cyan', g='green', m='magenta', r='red',
5151
w='white', y='yellow', k='black', d='black')
5252

53+
def run_stdin(stdin):
54+
"""
55+
Overwrite stdin reader from args as GTK does not supply a stdin/stdout
56+
as a tty.
57+
"""
58+
pass
59+
60+
bpython.args.run_stdin = run_stdin
5361

5462
class ArgspecFormatter(object):
5563
"""

0 commit comments

Comments
 (0)