diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 1ade688..99e4af1 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -318,34 +318,25 @@ class InteractiveShell(SingletonConfigurable): # deprecated prompt traits: prompt_in1 = Unicode('In [\\#]: ', - help="Deprecated, will be removed in IPython 5.0, use PromptManager.in_template" + help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." ).tag(config=True) prompt_in2 = Unicode(' .\\D.: ', - help="Deprecated, will be removed in IPython 5.0, use PromptManager.in2_template" + help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." ).tag(config=True) prompt_out = Unicode('Out[\\#]: ', - help="Deprecated, will be removed in IPython 5.0, use PromptManager.out_template" + help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." ).tag(config=True) prompts_pad_left = Bool(True, - help="Deprecated, will be removed in IPython 5.0, use PromptManager.justify" + help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." ).tag(config=True) @observe('prompt_in1', 'prompt_in2', 'prompt_out', 'prompt_pad_left') def _prompt_trait_changed(self, change): - table = { - 'prompt_in1' : 'in_template', - 'prompt_in2' : 'in2_template', - 'prompt_out' : 'out_template', - 'prompts_pad_left' : 'justify', - } name = change['name'] - warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}".format( - name=name, newname=table[name]) + warn("InteractiveShell.{name} is deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly.".format( + name=name) ) # protect against weird cases where self.config may not exist: - if self.config is not None: - # propagate to corresponding PromptManager trait - setattr(self.config.PromptManager, table[name], change['new']) show_rewritten_input = Bool(True, help="Show rewritten input, e.g. for autocall." @@ -441,6 +432,9 @@ class InteractiveShell(SingletonConfigurable): # This is where traits with a config_key argument are updated # from the values on config. super(InteractiveShell, self).__init__(**kwargs) + if 'PromptManager' in self.config: + warn('As of IPython 5.0 `PromptManager` config will have no effect' + ' and has been replaced by TerminalInteractiveShell.prompts_class') self.configurables = [self] # These are relatively independent and stateless diff --git a/IPython/core/magics/config.py b/IPython/core/magics/config.py index 4a17ba5..9505697 100644 --- a/IPython/core/magics/config.py +++ b/IPython/core/magics/config.py @@ -61,7 +61,6 @@ class ConfigMagics(Magics): PrefilterManager AliasManager IPCompleter - PromptManager DisplayFormatter To view what is configurable on a given class, just pass the class diff --git a/IPython/lib/lexers.py b/IPython/lib/lexers.py index f983a3d..82cc1a7 100644 --- a/IPython/lib/lexers.py +++ b/IPython/lib/lexers.py @@ -230,9 +230,12 @@ class IPythonConsoleLexer(Lexer): # The regexps used to determine what is input and what is output. # The default prompts for IPython are: # - # c.PromptManager.in_template = 'In [\#]: ' - # c.PromptManager.in2_template = ' .\D.: ' - # c.PromptManager.out_template = 'Out[\#]: ' + # in = 'In [#]: ' + # continuation = ' .D.: ' + # template = 'Out[#]: ' + # + # Where '#' is the 'prompt number' or 'execution count' and 'D' + # D is a number of dots matching the width of the execution count # in1_regex = r'In \[[0-9]+\]: ' in2_regex = r' \.\.+\.: ' diff --git a/IPython/terminal/ipapp.py b/IPython/terminal/ipapp.py index d0470a1..1d89a18 100755 --- a/IPython/terminal/ipapp.py +++ b/IPython/terminal/ipapp.py @@ -123,9 +123,7 @@ addflag('term-title', 'TerminalInteractiveShell.term_title', classic_config = Config() classic_config.InteractiveShell.cache_size = 0 classic_config.PlainTextFormatter.pprint = False -classic_config.PromptManager.in_template = '>>> ' -classic_config.PromptManager.in2_template = '... ' -classic_config.PromptManager.out_template = '' +classic_config.TerminalInteractiveShell.prompts_class='IPython.terminal.prompts.ClassicPrompts' classic_config.InteractiveShell.separate_in = '' classic_config.InteractiveShell.separate_out = '' classic_config.InteractiveShell.separate_out2 = '' diff --git a/IPython/terminal/ptshell.py b/IPython/terminal/ptshell.py index cf7fac1..dfeabcc 100644 --- a/IPython/terminal/ptshell.py +++ b/IPython/terminal/ptshell.py @@ -11,7 +11,7 @@ from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.utils.py3compat import PY3, cast_unicode_py2, input from IPython.utils.terminal import toggle_set_term_title, set_term_title from IPython.utils.process import abbrev_cwd -from traitlets import Bool, Unicode, Dict, Integer, observe, Instance +from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode from prompt_toolkit.filters import HasFocus, HasSelection, Condition, ViInsertMode, EmacsInsertMode, IsDone @@ -118,10 +118,12 @@ class TerminalInteractiveShell(InteractiveShell): help="Set the editor used by IPython (default to $EDITOR/vi/notepad)." ).tag(config=True) + prompts_class = Type(Prompts, config=True, help='Class used to generate Prompt token for prompt_toolkit') + prompts = Instance(Prompts) def _prompts_default(self): - return Prompts(self) + return self.prompts_class(self) @observe('prompts') def _(self, change): @@ -301,7 +303,7 @@ class TerminalInteractiveShell(InteractiveShell): Ask for a re computation of the application layout, if for example , some configuration options have changed. """ - if self._app: + if getattr(self, '._app', None): self._app.layout = create_prompt_layout(**self._layout_options()) def prompt_for_code(self): diff --git a/examples/Embedding/embed_class_long.py b/examples/Embedding/embed_class_long.py index 3697251..cbe9acb 100755 --- a/examples/Embedding/embed_class_long.py +++ b/examples/Embedding/embed_class_long.py @@ -17,16 +17,34 @@ from __future__ import print_function # Try running this code both at the command line and from inside IPython (with # %run example-embed.py) + +from IPython.terminal.prompts import Prompts, Token + +class CustomPrompt(Prompts): + + def in_prompt_tokens(self, cli=None): + + return [ + (Token.Prompt, 'In <'), + (Token.PromptNum, str(self.shell.execution_count)), + (Token.Prompt, '>: '), + ] + + def out_prompt_tokens(self): + return [ + (Token.OutPrompt, 'Out<'), + (Token.OutPromptNum, str(self.shell.execution_count)), + (Token.OutPrompt, '>: '), + ] + + from traitlets.config.loader import Config try: get_ipython except NameError: nested = 0 cfg = Config() - prompt_config = cfg.PromptManager - prompt_config.in_template = 'In <\\#>: ' - prompt_config.in2_template = ' .\\D.: ' - prompt_config.out_template = 'Out<\\#>: ' + cfg.TerminalInteractiveShell.prompts_class=CustomPrompt else: print("Running nested copies of IPython.") print("The prompts for the nested copy have been modified") @@ -45,13 +63,6 @@ ipshell = InteractiveShellEmbed(config=cfg, exit_msg = 'Leaving Interpreter, back to program.') # Make a second instance, you can have as many as you want. -cfg2 = cfg.copy() -prompt_config = cfg2.PromptManager -prompt_config.in_template = 'In2<\\#>: ' -if not nested: - prompt_config.in_template = 'In2<\\#>: ' - prompt_config.in2_template = ' .\\D.: ' - prompt_config.out_template = 'Out<\\#>: ' ipshell2 = InteractiveShellEmbed(config=cfg, banner1 = 'Second IPython instance.') @@ -95,7 +106,7 @@ print('\nBack in caller program, moving along...\n') # This is how the global banner and exit_msg can be reset at any point -ipshell.banner = 'Entering interpreter - New Banner' +ipshell.banner2 = 'Entering interpreter - New Banner' ipshell.exit_msg = 'Leaving interpreter - New exit_msg' def foo(m):