Skip to content

Commit 863d7e4

Browse files
fix display of non-ascii characters
--HG-- branch : scroll-frontend
1 parent 2489683 commit 863d7e4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

bpython/scrollfrontend/repl.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,28 @@
4242
#TODO options.interactive, .quiet
4343
#TODO execute file if in args
4444
#TODO working raw_input
45+
#TODO use events instead of length-one queues for interthread communication
4546

4647
from bpython.keys import cli_key_dispatch as key_dispatch
4748

49+
#TODO not that this object is custom, it should do more (not treated like a StringIO)
50+
class FakeStdout(object):
51+
def __init__(self):
52+
self.data = StringIO()
53+
def seek(self, pos, mode=0): return self.data.seek(pos, mode)
54+
def tell(self): return self.data.tell()
55+
def read(self, n=None):
56+
data = self.data.read()
57+
if isinstance(data, bytes):
58+
return data.decode('utf8')
59+
else:
60+
return data
61+
def write(self, msg):
62+
if isinstance(msg, bytes):
63+
return self.data.write(msg.encode('uft8'))
64+
else:
65+
return self.data.write(msg)
66+
4867
class FakeStdin(object):
4968
def __init__(self, on_receive_tuple):
5069
self.request_from_executing_code = Queue.Queue(maxsize=1)
@@ -162,7 +181,7 @@ def __enter__(self):
162181
self.orig_stdout = sys.stdout
163182
self.orig_stderr = sys.stderr
164183
self.orig_stdin = sys.stdin
165-
sys.stdout = StringIO()
184+
sys.stdout = FakeStdout()
166185
sys.stderr = StringIO()
167186
sys.stdin = self.stdin
168187
return self

0 commit comments

Comments
 (0)