From 83d273e24b28b9c06f0fa4f5bf90581db7c29be8 2017-01-10 14:10:27 From: Thomas Kluyver Date: 2017-01-10 14:10:27 Subject: [PATCH] Fix newline check when prompt consists of empty token --- diff --git a/IPython/terminal/prompts.py b/IPython/terminal/prompts.py index 7b916cd..2208852 100644 --- a/IPython/terminal/prompts.py +++ b/IPython/terminal/prompts.py @@ -68,10 +68,12 @@ class RichPromptDisplayHook(DisplayHook): if self.do_full_cache: tokens = self.shell.prompts.out_prompt_tokens() - if tokens and not tokens[-1][1].endswith('\n'): + prompt_txt = ''.join(s for t, s in tokens) + if prompt_txt and not prompt_txt.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: - sys.stdout.write(''.join(s for t, s in tokens)) + sys.stdout.write(prompt_txt)