Skip to content

Commit

Permalink
Naïve workaround of the bracketed-paste mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Jan 11, 2021
1 parent 02c3833 commit 92eb86c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pexpect/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def repl_run_command_async(repl, cmdlines, timeout=-1):
repl.child.kill(signal.SIGINT)
yield from repl._expect_prompt(timeout=1, async_=True)
raise ValueError("Continuation prompt found - input was incomplete:")
return u''.join(res + [repl.child.before])
return repl._strip_bracketed_paste(u''.join(res + [repl.child.before]))

class PatternWaiter(asyncio.Protocol):
transport = None
Expand Down
6 changes: 5 additions & 1 deletion pexpect/replwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def _expect_prompt(self, timeout=-1, async_=False):
return self.child.expect_exact([self.prompt, self.continuation_prompt],
timeout=timeout, async_=async_)

def _strip_bracketed_paste(self, text):
"""https://github.com/pexpect/pexpect/issues/669"""
return text.replace(u"\x1b[?2004l\r", u"").replace(u"\x1b[?2004h", u"")

def run_command(self, command, timeout=-1, async_=False):
"""Send a command to the REPL, wait for and return output.
Expand Down Expand Up @@ -106,7 +110,7 @@ def run_command(self, command, timeout=-1, async_=False):
self._expect_prompt(timeout=1)
raise ValueError("Continuation prompt found - input was incomplete:\n"
+ command)
return u''.join(res + [self.child.before])
return self._strip_bracketed_paste(u''.join(res + [self.child.before]))

def python(command=sys.executable):
"""Start a Python shell and return a :class:`REPLWrapper` object."""
Expand Down

0 comments on commit 92eb86c

Please sign in to comment.