Skip to content

Commit a5f3ba1

Browse files
committed
Initial start to provide a common object for our stdout and stderr streams. This will be shared over frontends and is related to ticket #149.
1 parent f83f14a commit a5f3ba1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

bpython/cli.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ def calculate_screen_lines(tokens, width, cursor=0):
116116
return lines
117117

118118

119+
class FakeStream(object):
120+
"""Provide a fake file object which calls functions on the interface
121+
provided."""
122+
123+
def __init__(self, interface):
124+
self.encoding = getpreferredencoding()
125+
self.interface = interface
126+
127+
def write(self, s):
128+
self.interface.write(s)
129+
130+
def writelines(self, l):
131+
for s in l:
132+
self.write(s)
133+
134+
def isatty(self):
135+
# some third party (amongst them mercurial) depend on this
136+
return True
137+
119138
class FakeStdin(object):
120139
"""Provide a fake stdin type for things like raw_input() etc."""
121140

@@ -655,9 +674,6 @@ def home(self, refresh=True):
655674
self.scr.refresh()
656675
return True
657676

658-
def isatty(self):
659-
return True
660-
661677
def lf(self):
662678
"""Process a linefeed character; it only needs to check the
663679
cursor position and move appropriately so it doesn't clear
@@ -1814,8 +1830,8 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
18141830
clirepl._C = cols
18151831

18161832
sys.stdin = FakeStdin(clirepl)
1817-
sys.stdout = clirepl
1818-
sys.stderr = clirepl
1833+
sys.stdout = FakeStream(clirepl)
1834+
sys.stderr = FakeStream(clirepl)
18191835

18201836
if args:
18211837
bpython.args.exec_code(interpreter, args)

0 commit comments

Comments
 (0)