diff --git a/jupyter_console/ptshell.py b/jupyter_console/ptshell.py index 4943dab..a4a30b4 100644 --- a/jupyter_console/ptshell.py +++ b/jupyter_console/ptshell.py @@ -19,6 +19,7 @@ from zmq import ZMQError from IPython.core import page +from IPython.core.interactiveshell import SeparateUnicode from traitlets import ( Bool, Integer, @@ -325,6 +326,10 @@ class ZMQTerminalInteractiveShell(SingletonConfigurable): config=True ) + separate_in = SeparateUnicode('\n').tag(config=True) + separate_out = SeparateUnicode('\n').tag(config=True) + separate_out2 = SeparateUnicode('\n').tag(config=True) + manager = Instance("jupyter_client.KernelManager", allow_none=True) client = Instance("jupyter_client.KernelClient", allow_none=True) @@ -398,6 +403,7 @@ def get_out_prompt_tokens(self): ] def print_out_prompt(self): + sys.stdout.write(self.separate_out) tokens = self.get_out_prompt_tokens() print_formatted_text(PygmentsTokens(tokens), end='', style = self.pt_cli.app.style) @@ -636,7 +642,7 @@ def set_doc(): async def interact(self, loop=None, display_banner=None): while self.keep_running: - print('\n', end='') + print(self.separate_in, end='') try: code = await self.prompt_for_code() @@ -900,6 +906,7 @@ def handle_iopub(self, msg_id=''): # For multi-line results, start a new line after prompt print() print(text_repr) + sys.stdout.write(self.separate_out2) # Remote: add new prompt if not self.from_here(sub_msg): diff --git a/jupyter_console/tests/test_console.py b/jupyter_console/tests/test_console.py index 83b5ee6..45ac47c 100644 --- a/jupyter_console/tests/test_console.py +++ b/jupyter_console/tests/test_console.py @@ -25,7 +25,26 @@ def test_console_starts(): p, pexpect, t = start_console() p.sendline("5") p.expect([r"Out\[\d+\]: 5", pexpect.EOF], timeout=t) - p.expect([r"In \[\d+\]", pexpect.EOF], timeout=t) + p.expect(["\n", "\n", r"In \[\d+\]", pexpect.EOF], timeout=t) + stop_console(p, pexpect, t) + +@flaky +@pytest.mark.skipif(should_skip, reason="not supported") +def test_console_starts_nonl(): + """test that `jupyter console` starts a terminal""" + p, pexpect, t = start_console(['--ZMQTerminalInteractiveShell.separate_in=""']) + p.sendline("5") + p.expect([r"Out\[\d+\]: 5", pexpect.EOF], timeout=t) + p.expect([r"(?