Commit 9dd8d9b9 authored by Juergen Nickelsen's avatar Juergen Nickelsen

fix line input() prompt issue

Once Python's input() prints the prompt itself, everything is fine.
Before, line editing did not know about the prompt and showed
confusing terminal output.
parent 3d743bff
......@@ -65,7 +65,10 @@ def repl(inp, fname, out=None):
while True:
if reader.interactive:
print("> ", end='', file=out, flush=True)
# We set the prompt at the start of reading an expression; it is
# emptied after the first line input(), and restored for the
# text expression here.
reader.prompt = "> "
ob =
if ob is not None:
# dbg.p(dbg.repl, "=> {o} ({t})".format(o=ob, t=type(ob)))
......@@ -200,6 +203,7 @@ class Reader():
self.lineLen = 0
self.linePos = 0
self.interactive = is_interactive(inp, out)
self.prompt = ""
def close(self):
def unread(self, ch):
......@@ -212,7 +216,10 @@ class Reader():
"Get a new line; return truish iff there was one."
if self.interactive:
line = input()
line = input(self.prompt)
# Prompt shall only be set at the beginning of an expression,
# for which it is said before the repl calls the read() method.
self.prompt = ""
except EOFError:
return False
line += "\n"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment