From e77ba5f0679eb44215d5d8b233e7161368296241 2023-12-31 10:29:36 From: Matthias Bussonnier Date: 2023-12-31 10:29:36 Subject: [PATCH] Include reviews from `@tornaria` --- diff --git a/docs/source/config/details.rst b/docs/source/config/details.rst index 2e7e5be..69dad2c 100644 --- a/docs/source/config/details.rst +++ b/docs/source/config/details.rst @@ -33,7 +33,7 @@ which defines the defaults. The required interface is like this: Prompt style definition. *shell* is a reference to the :class:`~.TerminalInteractiveShell` instance. - .. method:: in_prompt_tokens(cli=None) + .. method:: in_prompt_tokens() continuation_prompt_tokens(self, width=None) rewrite_prompt_tokens() out_prompt_tokens() @@ -43,8 +43,6 @@ which defines the defaults. The required interface is like this: For continuation prompts, *width* is an integer representing the width of the prompt area in terminal columns. - *cli*, where used, is the prompt_toolkit ``CommandLineInterface`` instance. - This is mainly for compatibility with the API prompt_toolkit expects. Here is an example Prompt class that will show the current working directory in the input prompt: @@ -55,7 +53,7 @@ in the input prompt: import os class MyPrompt(Prompts): - def in_prompt_tokens(self, cli=None): + def in_prompt_tokens(self): return [(Token, os.getcwd()), (Token.Prompt, ' >>>')] diff --git a/examples/Embedding/embed_class_long.py b/examples/Embedding/embed_class_long.py index 53a31cf..0cd09d0 100755 --- a/examples/Embedding/embed_class_long.py +++ b/examples/Embedding/embed_class_long.py @@ -18,26 +18,26 @@ The code in this file is deliberately extra-verbose, meant for learning.""" # %run example-embed.py) from IPython.terminal.prompts import Prompts, Token +from traitlets.config.loader import Config class CustomPrompt(Prompts): - def in_prompt_tokens(self, cli=None): + def in_prompt_tokens(self): - return [ + return [ (Token.Prompt, 'In <'), (Token.PromptNum, str(self.shell.execution_count)), (Token.Prompt, '>: '), ] def out_prompt_tokens(self): - return [ + return [ (Token.OutPrompt, 'Out<'), (Token.OutPromptNum, str(self.shell.execution_count)), (Token.OutPrompt, '>: '), ] -from traitlets.config.loader import Config try: get_ipython except NameError: diff --git a/examples/utils/cwd_prompt.py b/examples/utils/cwd_prompt.py index 1d1b03a..0fa69d6 100644 --- a/examples/utils/cwd_prompt.py +++ b/examples/utils/cwd_prompt.py @@ -6,9 +6,12 @@ import os class MyPrompt(Prompts): - def in_prompt_tokens(self, cli=None): - return [(Token, os.getcwd()), - (Token.Prompt, '>>>')] + def in_prompt_tokens(self): + return [ + (Token, os.getcwd()), + (Token.Prompt, ">>>") + ] + def load_ipython_extension(shell): new_prompts = MyPrompt(shell) @@ -20,7 +23,3 @@ def unload_ipython_extension(shell): print("cannot unload") else: shell.prompts = shell.prompts.old_prompts - - - -