Show More
@@ -318,34 +318,25 b' class InteractiveShell(SingletonConfigurable):' | |||||
318 | # deprecated prompt traits: |
|
318 | # deprecated prompt traits: | |
319 |
|
319 | |||
320 | prompt_in1 = Unicode('In [\\#]: ', |
|
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 | ).tag(config=True) |
|
322 | ).tag(config=True) | |
323 | prompt_in2 = Unicode(' .\\D.: ', |
|
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 | ).tag(config=True) |
|
325 | ).tag(config=True) | |
326 | prompt_out = Unicode('Out[\\#]: ', |
|
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 | ).tag(config=True) |
|
328 | ).tag(config=True) | |
329 | prompts_pad_left = Bool(True, |
|
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 | ).tag(config=True) |
|
331 | ).tag(config=True) | |
332 |
|
332 | |||
333 | @observe('prompt_in1', 'prompt_in2', 'prompt_out', 'prompt_pad_left') |
|
333 | @observe('prompt_in1', 'prompt_in2', 'prompt_out', 'prompt_pad_left') | |
334 | def _prompt_trait_changed(self, change): |
|
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 | name = change['name'] |
|
335 | name = change['name'] | |
342 | warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}".format( |
|
336 | warn("InteractiveShell.{name} is deprecated since IPython 4.0 and ignored since 5.0, set IPython.terminal.ptshell.TerminalInteractiveShell.prompts object directly.".format( | |
343 |
name=name |
|
337 | name=name) | |
344 | ) |
|
338 | ) | |
345 | # protect against weird cases where self.config may not exist: |
|
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 | show_rewritten_input = Bool(True, |
|
341 | show_rewritten_input = Bool(True, | |
351 | help="Show rewritten input, e.g. for autocall." |
|
342 | help="Show rewritten input, e.g. for autocall." | |
@@ -441,6 +432,9 b' class InteractiveShell(SingletonConfigurable):' | |||||
441 | # This is where traits with a config_key argument are updated |
|
432 | # This is where traits with a config_key argument are updated | |
442 | # from the values on config. |
|
433 | # from the values on config. | |
443 | super(InteractiveShell, self).__init__(**kwargs) |
|
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 | self.configurables = [self] |
|
438 | self.configurables = [self] | |
445 |
|
439 | |||
446 | # These are relatively independent and stateless |
|
440 | # These are relatively independent and stateless |
@@ -61,7 +61,6 b' class ConfigMagics(Magics):' | |||||
61 | PrefilterManager |
|
61 | PrefilterManager | |
62 | AliasManager |
|
62 | AliasManager | |
63 | IPCompleter |
|
63 | IPCompleter | |
64 | PromptManager |
|
|||
65 | DisplayFormatter |
|
64 | DisplayFormatter | |
66 |
|
65 | |||
67 | To view what is configurable on a given class, just pass the class |
|
66 | To view what is configurable on a given class, just pass the class |
@@ -230,9 +230,12 b' class IPythonConsoleLexer(Lexer):' | |||||
230 | # The regexps used to determine what is input and what is output. |
|
230 | # The regexps used to determine what is input and what is output. | |
231 | # The default prompts for IPython are: |
|
231 | # The default prompts for IPython are: | |
232 | # |
|
232 | # | |
233 | # c.PromptManager.in_template = 'In [\#]: ' |
|
233 | # in = 'In [#]: ' | |
234 |
# |
|
234 | # continuation = ' .D.: ' | |
235 |
# |
|
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 | in1_regex = r'In \[[0-9]+\]: ' |
|
240 | in1_regex = r'In \[[0-9]+\]: ' | |
238 | in2_regex = r' \.\.+\.: ' |
|
241 | in2_regex = r' \.\.+\.: ' |
@@ -123,9 +123,7 b" addflag('term-title', 'TerminalInteractiveShell.term_title'," | |||||
123 | classic_config = Config() |
|
123 | classic_config = Config() | |
124 | classic_config.InteractiveShell.cache_size = 0 |
|
124 | classic_config.InteractiveShell.cache_size = 0 | |
125 | classic_config.PlainTextFormatter.pprint = False |
|
125 | classic_config.PlainTextFormatter.pprint = False | |
126 | classic_config.PromptManager.in_template = '>>> ' |
|
126 | classic_config.TerminalInteractiveShell.prompts_class='IPython.terminal.prompts.ClassicPrompts' | |
127 | classic_config.PromptManager.in2_template = '... ' |
|
|||
128 | classic_config.PromptManager.out_template = '' |
|
|||
129 | classic_config.InteractiveShell.separate_in = '' |
|
127 | classic_config.InteractiveShell.separate_in = '' | |
130 | classic_config.InteractiveShell.separate_out = '' |
|
128 | classic_config.InteractiveShell.separate_out = '' | |
131 | classic_config.InteractiveShell.separate_out2 = '' |
|
129 | classic_config.InteractiveShell.separate_out2 = '' |
@@ -11,7 +11,7 b' from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC' | |||||
11 | from IPython.utils.py3compat import PY3, cast_unicode_py2, input |
|
11 | from IPython.utils.py3compat import PY3, cast_unicode_py2, input | |
12 | from IPython.utils.terminal import toggle_set_term_title, set_term_title |
|
12 | from IPython.utils.terminal import toggle_set_term_title, set_term_title | |
13 | from IPython.utils.process import abbrev_cwd |
|
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 | from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode |
|
16 | from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode | |
17 | from prompt_toolkit.filters import HasFocus, HasSelection, Condition, ViInsertMode, EmacsInsertMode, IsDone |
|
17 | from prompt_toolkit.filters import HasFocus, HasSelection, Condition, ViInsertMode, EmacsInsertMode, IsDone | |
@@ -118,10 +118,12 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
118 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad)." |
|
118 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad)." | |
119 | ).tag(config=True) |
|
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 | prompts = Instance(Prompts) |
|
123 | prompts = Instance(Prompts) | |
122 |
|
124 | |||
123 | def _prompts_default(self): |
|
125 | def _prompts_default(self): | |
124 |
return |
|
126 | return self.prompts_class(self) | |
125 |
|
127 | |||
126 | @observe('prompts') |
|
128 | @observe('prompts') | |
127 | def _(self, change): |
|
129 | def _(self, change): | |
@@ -301,7 +303,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
301 | Ask for a re computation of the application layout, if for example , |
|
303 | Ask for a re computation of the application layout, if for example , | |
302 | some configuration options have changed. |
|
304 | some configuration options have changed. | |
303 | """ |
|
305 | """ | |
304 | if self._app: |
|
306 | if getattr(self, '._app', None): | |
305 | self._app.layout = create_prompt_layout(**self._layout_options()) |
|
307 | self._app.layout = create_prompt_layout(**self._layout_options()) | |
306 |
|
308 | |||
307 | def prompt_for_code(self): |
|
309 | def prompt_for_code(self): |
@@ -17,16 +17,34 b' from __future__ import print_function' | |||||
17 |
|
17 | |||
18 | # Try running this code both at the command line and from inside IPython (with |
|
18 | # Try running this code both at the command line and from inside IPython (with | |
19 | # %run example-embed.py) |
|
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 | from traitlets.config.loader import Config |
|
41 | from traitlets.config.loader import Config | |
21 | try: |
|
42 | try: | |
22 | get_ipython |
|
43 | get_ipython | |
23 | except NameError: |
|
44 | except NameError: | |
24 | nested = 0 |
|
45 | nested = 0 | |
25 | cfg = Config() |
|
46 | cfg = Config() | |
26 | prompt_config = cfg.PromptManager |
|
47 | cfg.TerminalInteractiveShell.prompts_class=CustomPrompt | |
27 | prompt_config.in_template = 'In <\\#>: ' |
|
|||
28 | prompt_config.in2_template = ' .\\D.: ' |
|
|||
29 | prompt_config.out_template = 'Out<\\#>: ' |
|
|||
30 | else: |
|
48 | else: | |
31 | print("Running nested copies of IPython.") |
|
49 | print("Running nested copies of IPython.") | |
32 | print("The prompts for the nested copy have been modified") |
|
50 | print("The prompts for the nested copy have been modified") | |
@@ -45,13 +63,6 b' ipshell = InteractiveShellEmbed(config=cfg,' | |||||
45 | exit_msg = 'Leaving Interpreter, back to program.') |
|
63 | exit_msg = 'Leaving Interpreter, back to program.') | |
46 |
|
64 | |||
47 | # Make a second instance, you can have as many as you want. |
|
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 | ipshell2 = InteractiveShellEmbed(config=cfg, |
|
66 | ipshell2 = InteractiveShellEmbed(config=cfg, | |
56 | banner1 = 'Second IPython instance.') |
|
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 | # This is how the global banner and exit_msg can be reset at any point |
|
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 | ipshell.exit_msg = 'Leaving interpreter - New exit_msg' |
|
110 | ipshell.exit_msg = 'Leaving interpreter - New exit_msg' | |
100 |
|
111 | |||
101 | def foo(m): |
|
112 | def foo(m): |
General Comments 0
You need to be logged in to leave comments.
Login now