diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py index 41d03d2..ad3cc27 100644 --- a/IPython/core/displayhook.py +++ b/IPython/core/displayhook.py @@ -149,6 +149,9 @@ class DisplayHook(Configurable): """ return self.shell.display_formatter.format(result) + # This can be set to True by the write_output_prompt method in a subclass + prompt_end_newline = False + def write_format_data(self, format_dict, md_dict=None): """Write the format data dict to the frontend. @@ -179,8 +182,7 @@ class DisplayHook(Configurable): # because the expansion may add ANSI escapes that will interfere # with our ability to determine whether or not we should add # a newline. - prompt_template = self.shell.prompt_manager.out_template - if prompt_template and not prompt_template.endswith('\n'): + if not self.prompt_end_newline: # But avoid extraneous empty lines. result_repr = '\n' + result_repr diff --git a/IPython/terminal/prompts.py b/IPython/terminal/prompts.py index fdfc9f9..8e42967 100644 --- a/IPython/terminal/prompts.py +++ b/IPython/terminal/prompts.py @@ -42,8 +42,11 @@ class RichPromptDisplayHook(DisplayHook): """Subclass of base display hook using coloured prompt""" def write_output_prompt(self): sys.stdout.write(self.shell.separate_out) + self.prompt_end_newline = False if self.do_full_cache: tokens = self.shell.prompts.out_prompt_tokens() + if tokens and tokens[-1][1].endswith('\n'): + self.prompt_end_newline = True if self.shell.pt_cli: self.shell.pt_cli.print_tokens(tokens) else: