From 4c6e63d08b2dff0eaeb8c357108644989f5b290c 2017-01-09 15:45:21 From: Thomas Kluyver Date: 2017-01-09 15:45:21 Subject: [PATCH] Empty prompt effectively ends with newline Closes gh-10138 --- diff --git a/IPython/terminal/prompts.py b/IPython/terminal/prompts.py index 55e08be..7b916cd 100644 --- a/IPython/terminal/prompts.py +++ b/IPython/terminal/prompts.py @@ -62,11 +62,15 @@ 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 we're not displaying a prompt, it effectively ends with a newline, + # because the output will be left-aligned. + self.prompt_end_newline = True + 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 tokens and not tokens[-1][1].endswith('\n'): + # Ask for a newline before multiline output + self.prompt_end_newline = False if self.shell.pt_cli: self.shell.pt_cli.print_tokens(tokens) else: