Skip to content

Commit

Permalink
Include reviews from @tornaria
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Dec 31, 2023
1 parent 96afe65 commit e77ba5f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
6 changes: 2 additions & 4 deletions docs/source/config/details.rst
Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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, ' >>>')]
Expand Down
8 changes: 4 additions & 4 deletions examples/Embedding/embed_class_long.py
Expand Up @@ -18,26 +18,26 @@
# %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:
Expand Down
13 changes: 6 additions & 7 deletions examples/utils/cwd_prompt.py
Expand Up @@ -6,9 +6,12 @@

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)
Expand All @@ -20,7 +23,3 @@ def unload_ipython_extension(shell):
print("cannot unload")
else:
shell.prompts = shell.prompts.old_prompts




0 comments on commit e77ba5f

Please sign in to comment.