Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow overriding sys.stderr before calling print_error #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions yapps/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,17 @@ def get_pos(self):
# output += '%s\n' % (repr(t),)
# return output

def print_line_with_pointer(self, pos, length=0, out=sys.stderr):
def print_line_with_pointer(self, pos, length=0, out=None):
"""Print the line of 'text' that includes position 'p',
along with a second line with a single caret (^) at position p"""

if out is None:
out = sys.stderr

file,line,p = pos
if file != self.filename:
if self.stack: return self.stack.print_line_with_pointer(pos,length=length,out=out)
print >>out, "(%s: not in input buffer)" % file
print("(%s: not in input buffer)" % file, file=out)
return

text = self.input
Expand All @@ -198,7 +201,7 @@ def print_line_with_pointer(self, pos, length=0, out=sys.stderr):
break
spos = cr+1
else:
print >>out, "(%s:%d not in input buffer)" % (file,origline)
print("(%s:%d not in input buffer)" % (file,origline), file=out)
return

# Now try printing part of the line
Expand Down Expand Up @@ -227,8 +230,8 @@ def print_line_with_pointer(self, pos, length=0, out=sys.stderr):
p = p - 7

# Now print the string, along with an indicator
print >>out, '> ',text
print >>out, '> ',' '*p + '^'
print('> ',text, file=out)
print('> ',' '*p + '^', file=out)

def grab_input(self):
"""Get more input if possible."""
Expand Down