Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion bpython/curtsiesfrontend/coderunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,30 @@ def request_from_main_greenlet(self, force_refresh=False):


class FakeOutput(object):
def __init__(self, coderunner, on_write):
def __init__(self, coderunner, on_write, fileno=1):
"""Fakes sys.stdout or sys.stderr

on_write should always take unicode

fileno should be the fileno that on_write will
output to (e.g. 1 for standard output).
"""
self.coderunner = coderunner
self.on_write = on_write
self.real_fileno = fileno

def write(self, s, *args, **kwargs):
if not py3 and isinstance(s, str):
s = s.decode(getpreferredencoding(), 'ignore')
self.on_write(s, *args, **kwargs)
return self.coderunner.request_from_main_greenlet(force_refresh=True)

# Some applications which use curses require that sys.stdout
# have a method called fileno. One example is pwntools. This
# is not a widespread issue, but is annoying.
def fileno(self):
return self.real_fileno

def writelines(self, l):
for s in l:
self.write(s)
Expand Down
5 changes: 3 additions & 2 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ def __init__(self,
self.orig_tcattrs = orig_tcattrs

self.coderunner = CodeRunner(self.interp, self.request_refresh)
self.stdout = FakeOutput(self.coderunner, self.send_to_stdout)
self.stderr = FakeOutput(self.coderunner, self.send_to_stderr)
# Added explicit fileno definitions to reflect to backend device
self.stdout = FakeOutput(self.coderunner, self.send_to_stdout, fileno=1)
self.stderr = FakeOutput(self.coderunner, self.send_to_stderr, fileno=2)
self.stdin = FakeStdin(self.coderunner, self, self.edit_keys)

# next paint should clear screen
Expand Down