Show More
@@ -318,34 +318,25 b' class InteractiveShell(SingletonConfigurable):' | |||
|
318 | 318 | # deprecated prompt traits: |
|
319 | 319 | |
|
320 | 320 | prompt_in1 = Unicode('In [\\#]: ', |
|
321 | help="Deprecated, will be removed in IPython 5.0, use PromptManager.in_template" | |
|
321 | help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." | |
|
322 | 322 | ).tag(config=True) |
|
323 | 323 | prompt_in2 = Unicode(' .\\D.: ', |
|
324 | help="Deprecated, will be removed in IPython 5.0, use PromptManager.in2_template" | |
|
324 | help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." | |
|
325 | 325 | ).tag(config=True) |
|
326 | 326 | prompt_out = Unicode('Out[\\#]: ', |
|
327 | help="Deprecated, will be removed in IPython 5.0, use PromptManager.out_template" | |
|
327 | help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." | |
|
328 | 328 | ).tag(config=True) |
|
329 | 329 | prompts_pad_left = Bool(True, |
|
330 | help="Deprecated, will be removed in IPython 5.0, use PromptManager.justify" | |
|
330 | help="Deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly." | |
|
331 | 331 | ).tag(config=True) |
|
332 | 332 | |
|
333 | 333 | @observe('prompt_in1', 'prompt_in2', 'prompt_out', 'prompt_pad_left') |
|
334 | 334 | def _prompt_trait_changed(self, change): |
|
335 | table = { | |
|
336 | 'prompt_in1' : 'in_template', | |
|
337 | 'prompt_in2' : 'in2_template', | |
|
338 | 'prompt_out' : 'out_template', | |
|
339 | 'prompts_pad_left' : 'justify', | |
|
340 | } | |
|
341 | 335 | name = change['name'] |
|
342 | warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}".format( | |
|
343 |
name=name |
|
|
336 | warn("InteractiveShell.{name} is deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly.".format( | |
|
337 | name=name) | |
|
344 | 338 | ) |
|
345 | 339 | # protect against weird cases where self.config may not exist: |
|
346 | if self.config is not None: | |
|
347 | # propagate to corresponding PromptManager trait | |
|
348 | setattr(self.config.PromptManager, table[name], change['new']) | |
|
349 | 340 | |
|
350 | 341 | show_rewritten_input = Bool(True, |
|
351 | 342 | help="Show rewritten input, e.g. for autocall." |
@@ -441,6 +432,9 b' class InteractiveShell(SingletonConfigurable):' | |||
|
441 | 432 | # This is where traits with a config_key argument are updated |
|
442 | 433 | # from the values on config. |
|
443 | 434 | super(InteractiveShell, self).__init__(**kwargs) |
|
435 | if 'PromptManager' in self.config: | |
|
436 | warn('As of IPython 5.0 `PromptManager` config will have no effect' | |
|
437 | ' and has been replaced by TerminalInteractiveShell.prompts_class') | |
|
444 | 438 | self.configurables = [self] |
|
445 | 439 | |
|
446 | 440 | # These are relatively independent and stateless |
@@ -61,7 +61,6 b' class ConfigMagics(Magics):' | |||
|
61 | 61 | PrefilterManager |
|
62 | 62 | AliasManager |
|
63 | 63 | IPCompleter |
|
64 | PromptManager | |
|
65 | 64 | DisplayFormatter |
|
66 | 65 | |
|
67 | 66 | To view what is configurable on a given class, just pass the class |
@@ -230,9 +230,12 b' class IPythonConsoleLexer(Lexer):' | |||
|
230 | 230 | # The regexps used to determine what is input and what is output. |
|
231 | 231 | # The default prompts for IPython are: |
|
232 | 232 | # |
|
233 | # c.PromptManager.in_template = 'In [\#]: ' | |
|
234 |
# |
|
|
235 |
# |
|
|
233 | # in = 'In [#]: ' | |
|
234 | # continuation = ' .D.: ' | |
|
235 | # template = 'Out[#]: ' | |
|
236 | # | |
|
237 | # Where '#' is the 'prompt number' or 'execution count' and 'D' | |
|
238 | # D is a number of dots matching the width of the execution count | |
|
236 | 239 | # |
|
237 | 240 | in1_regex = r'In \[[0-9]+\]: ' |
|
238 | 241 | in2_regex = r' \.\.+\.: ' |
@@ -123,9 +123,7 b" addflag('term-title', 'TerminalInteractiveShell.term_title'," | |||
|
123 | 123 | classic_config = Config() |
|
124 | 124 | classic_config.InteractiveShell.cache_size = 0 |
|
125 | 125 | classic_config.PlainTextFormatter.pprint = False |
|
126 | classic_config.PromptManager.in_template = '>>> ' | |
|
127 | classic_config.PromptManager.in2_template = '... ' | |
|
128 | classic_config.PromptManager.out_template = '' | |
|
126 | classic_config.TerminalInteractiveShell.prompts_class='IPython.terminal.prompts.ClassicPrompts' | |
|
129 | 127 | classic_config.InteractiveShell.separate_in = '' |
|
130 | 128 | classic_config.InteractiveShell.separate_out = '' |
|
131 | 129 | classic_config.InteractiveShell.separate_out2 = '' |
@@ -11,7 +11,7 b' from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC' | |||
|
11 | 11 | from IPython.utils.py3compat import PY3, cast_unicode_py2, input |
|
12 | 12 | from IPython.utils.terminal import toggle_set_term_title, set_term_title |
|
13 | 13 | from IPython.utils.process import abbrev_cwd |
|
14 | from traitlets import Bool, Unicode, Dict, Integer, observe, Instance | |
|
14 | from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type | |
|
15 | 15 | |
|
16 | 16 | from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode |
|
17 | 17 | from prompt_toolkit.filters import HasFocus, HasSelection, Condition, ViInsertMode, EmacsInsertMode, IsDone |
@@ -118,10 +118,12 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
118 | 118 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad)." |
|
119 | 119 | ).tag(config=True) |
|
120 | 120 | |
|
121 | prompts_class = Type(Prompts, config=True, help='Class used to generate Prompt token for prompt_toolkit') | |
|
122 | ||
|
121 | 123 | prompts = Instance(Prompts) |
|
122 | 124 | |
|
123 | 125 | def _prompts_default(self): |
|
124 |
return |
|
|
126 | return self.prompts_class(self) | |
|
125 | 127 | |
|
126 | 128 | @observe('prompts') |
|
127 | 129 | def _(self, change): |
@@ -301,7 +303,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
301 | 303 | Ask for a re computation of the application layout, if for example , |
|
302 | 304 | some configuration options have changed. |
|
303 | 305 | """ |
|
304 | if self._app: | |
|
306 | if getattr(self, '._app', None): | |
|
305 | 307 | self._app.layout = create_prompt_layout(**self._layout_options()) |
|
306 | 308 | |
|
307 | 309 | def prompt_for_code(self): |
@@ -17,16 +17,34 b' from __future__ import print_function' | |||
|
17 | 17 | |
|
18 | 18 | # Try running this code both at the command line and from inside IPython (with |
|
19 | 19 | # %run example-embed.py) |
|
20 | ||
|
21 | from IPython.terminal.prompts import Prompts, Token | |
|
22 | ||
|
23 | class CustomPrompt(Prompts): | |
|
24 | ||
|
25 | def in_prompt_tokens(self, cli=None): | |
|
26 | ||
|
27 | return [ | |
|
28 | (Token.Prompt, 'In <'), | |
|
29 | (Token.PromptNum, str(self.shell.execution_count)), | |
|
30 | (Token.Prompt, '>: '), | |
|
31 | ] | |
|
32 | ||
|
33 | def out_prompt_tokens(self): | |
|
34 | return [ | |
|
35 | (Token.OutPrompt, 'Out<'), | |
|
36 | (Token.OutPromptNum, str(self.shell.execution_count)), | |
|
37 | (Token.OutPrompt, '>: '), | |
|
38 | ] | |
|
39 | ||
|
40 | ||
|
20 | 41 | from traitlets.config.loader import Config |
|
21 | 42 | try: |
|
22 | 43 | get_ipython |
|
23 | 44 | except NameError: |
|
24 | 45 | nested = 0 |
|
25 | 46 | cfg = Config() |
|
26 | prompt_config = cfg.PromptManager | |
|
27 | prompt_config.in_template = 'In <\\#>: ' | |
|
28 | prompt_config.in2_template = ' .\\D.: ' | |
|
29 | prompt_config.out_template = 'Out<\\#>: ' | |
|
47 | cfg.TerminalInteractiveShell.prompts_class=CustomPrompt | |
|
30 | 48 | else: |
|
31 | 49 | print("Running nested copies of IPython.") |
|
32 | 50 | print("The prompts for the nested copy have been modified") |
@@ -45,13 +63,6 b' ipshell = InteractiveShellEmbed(config=cfg,' | |||
|
45 | 63 | exit_msg = 'Leaving Interpreter, back to program.') |
|
46 | 64 | |
|
47 | 65 | # Make a second instance, you can have as many as you want. |
|
48 | cfg2 = cfg.copy() | |
|
49 | prompt_config = cfg2.PromptManager | |
|
50 | prompt_config.in_template = 'In2<\\#>: ' | |
|
51 | if not nested: | |
|
52 | prompt_config.in_template = 'In2<\\#>: ' | |
|
53 | prompt_config.in2_template = ' .\\D.: ' | |
|
54 | prompt_config.out_template = 'Out<\\#>: ' | |
|
55 | 66 | ipshell2 = InteractiveShellEmbed(config=cfg, |
|
56 | 67 | banner1 = 'Second IPython instance.') |
|
57 | 68 | |
@@ -95,7 +106,7 b" print('\\nBack in caller program, moving along...\\n')" | |||
|
95 | 106 | |
|
96 | 107 | |
|
97 | 108 | # This is how the global banner and exit_msg can be reset at any point |
|
98 | ipshell.banner = 'Entering interpreter - New Banner' | |
|
109 | ipshell.banner2 = 'Entering interpreter - New Banner' | |
|
99 | 110 | ipshell.exit_msg = 'Leaving interpreter - New exit_msg' |
|
100 | 111 | |
|
101 | 112 | def foo(m): |
General Comments 0
You need to be logged in to leave comments.
Login now