diff --git a/rlipython/shell.py b/rlipython/shell.py index bd5fabf..ac0346f 100644 --- a/rlipython/shell.py +++ b/rlipython/shell.py @@ -14,7 +14,7 @@ from IPython.core.error import TryNext, UsageError from IPython.core.usage import interactive_usage -from IPython.core.inputsplitter import ESC_MAGIC +from IPython.core.inputtransformer2 import ESC_MAGIC from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.terminal.magics import TerminalMagics from IPython.utils.contexts import NoOpContext @@ -152,6 +152,10 @@ class TerminalInteractiveShell(InteractiveShell): default.""", ) + # Store the number of spaces to use to indent the next line + # Can be either an integer or None + _indent_spaces = None + _term_reset = "\033[0m" # This is ugly because not only do we have a bunch of ansi escape # sequences, but we also have to wrap each escape code in \001 and \002 @@ -365,6 +369,11 @@ def pre_readline(self): self.readline.insert_text(self.rl_next_input) self.rl_next_input = None + def _indent_current_str(self): + """Return the current level of indentation as a string""" + n = 0 if self._indent_spaces is None else self._indent_spaces + return n * " " + def refill_readline_hist(self): # Load the last 1000 lines from history self.readline.clear_history() @@ -513,6 +522,7 @@ def interact(self, display_banner=None): # exit_now is set by a call to %Exit or %Quit, through the # ask_exit callback. + self.lines_waiting = [] while not self.exit_now: self.hooks.pre_prompt_hook() if more: @@ -544,7 +554,9 @@ def interact(self, display_banner=None): #double-guard against keyboardinterrupts during kbdint handling try: self.write('\n' + self.get_exception_only()) - source_raw = self.input_splitter.raw_reset() + source_raw = '\n'.join(self.lines_waiting) + self.lines_waiting = [] + self._indent_spaces = None hlen_b4_cell = \ self._replace_rlhist_multiline(source_raw, hlen_b4_cell) more = False @@ -568,8 +580,10 @@ def interact(self, display_banner=None): self.showtraceback() else: try: - self.input_splitter.push(line) - more = self.input_splitter.push_accepts_more() + self.lines_waiting.append(line) + status, next_indent = self.input_splitter.check_complete('\n'.join(self.lines_waiting)) + self._indent_spaces = next_indent + more = status == 'incomplete' except SyntaxError: # Run the code directly - run_cell takes care of displaying # the exception. @@ -578,7 +592,8 @@ def interact(self, display_banner=None): self.autoedit_syntax): self.edit_syntax_error() if not more: - source_raw = self.input_splitter.raw_reset() + source_raw = '\n'.join(self.lines_waiting) + self.lines_waiting = [] self.run_cell(source_raw, store_history=True) hlen_b4_cell = \ self._replace_rlhist_multiline(source_raw, hlen_b4_cell) diff --git a/setup.py b/setup.py index e9a7c61..e093b1c 100644 --- a/setup.py +++ b/setup.py @@ -21,12 +21,12 @@ name='rlipython', version='0.1.2', packages=['rlipython',], - install_requires=["ipython>5.3"], + install_requires=["ipython>=7.0.0"], extras_requires=extras_requires, license='BSD', author='The IPython Development Team', author_email='ipython-dev@python.org', url='https://github.com/ipython/rlipython', - description="readline integration for IPython 5.4+ and 6.0+", + description="readline integration for IPython 7.0+", long_description=description )