From 397b33c6cfb91bba92e52358de3edee47f58b22a 2023-12-07 19:40:42 From: Chris Hamill Date: 2023-12-07 19:40:42 Subject: [PATCH] Add line numbers to default prompt. --- diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 997fd82..4a063d4 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -753,7 +753,7 @@ class TerminalInteractiveShell(InteractiveShell): "message": get_message, "prompt_continuation": ( lambda width, lineno, is_soft_wrap: PygmentsTokens( - self.prompts.continuation_prompt_tokens(width) + self.prompts.continuation_prompt_tokens(width, lineno=lineno) ) ), "multiline": True, diff --git a/IPython/terminal/prompts.py b/IPython/terminal/prompts.py index 3f5c07b..8a1176f 100644 --- a/IPython/terminal/prompts.py +++ b/IPython/terminal/prompts.py @@ -28,8 +28,9 @@ class Prompts(object): def in_prompt_tokens(self): return [ - (Token.Prompt, self.vi_mode() ), - (Token.Prompt, 'In ['), + (Token.Prompt, self.vi_mode()), + (Token.Prompt, "1 | "), + (Token.Prompt, "In ["), (Token.PromptNum, str(self.shell.execution_count)), (Token.Prompt, ']: '), ] @@ -37,11 +38,15 @@ class Prompts(object): def _width(self): return fragment_list_width(self.in_prompt_tokens()) - def continuation_prompt_tokens(self, width=None): + def continuation_prompt_tokens(self, width=None, *, lineno=None): if width is None: width = self._width() + prefix = " " * len(self.vi_mode()) + str(lineno + 1) + " | " return [ - (Token.Prompt, (' ' * (width - 5)) + '...: '), + ( + Token.Prompt, + prefix + (" " * (width - len(prefix) - 5)) + "...: ", + ), ] def rewrite_prompt_tokens(self):