Show More
@@ -33,7 +33,7 b' which defines the defaults. The required interface is like this:' | |||||
33 | Prompt style definition. *shell* is a reference to the |
|
33 | Prompt style definition. *shell* is a reference to the | |
34 | :class:`~.TerminalInteractiveShell` instance. |
|
34 | :class:`~.TerminalInteractiveShell` instance. | |
35 |
|
35 | |||
36 |
.. method:: in_prompt_tokens( |
|
36 | .. method:: in_prompt_tokens() | |
37 | continuation_prompt_tokens(self, width=None) |
|
37 | continuation_prompt_tokens(self, width=None) | |
38 | rewrite_prompt_tokens() |
|
38 | rewrite_prompt_tokens() | |
39 | out_prompt_tokens() |
|
39 | out_prompt_tokens() | |
@@ -43,8 +43,6 b' which defines the defaults. The required interface is like this:' | |||||
43 | For continuation prompts, *width* is an integer representing the width of |
|
43 | For continuation prompts, *width* is an integer representing the width of | |
44 | the prompt area in terminal columns. |
|
44 | the prompt area in terminal columns. | |
45 |
|
45 | |||
46 | *cli*, where used, is the prompt_toolkit ``CommandLineInterface`` instance. |
|
|||
47 | This is mainly for compatibility with the API prompt_toolkit expects. |
|
|||
48 |
|
46 | |||
49 | Here is an example Prompt class that will show the current working directory |
|
47 | Here is an example Prompt class that will show the current working directory | |
50 | in the input prompt: |
|
48 | in the input prompt: | |
@@ -55,7 +53,7 b' in the input prompt:' | |||||
55 | import os |
|
53 | import os | |
56 |
|
54 | |||
57 | class MyPrompt(Prompts): |
|
55 | class MyPrompt(Prompts): | |
58 |
def in_prompt_tokens(self |
|
56 | def in_prompt_tokens(self): | |
59 | return [(Token, os.getcwd()), |
|
57 | return [(Token, os.getcwd()), | |
60 | (Token.Prompt, ' >>>')] |
|
58 | (Token.Prompt, ' >>>')] | |
61 |
|
59 |
@@ -18,26 +18,26 b' The code in this file is deliberately extra-verbose, meant for learning."""' | |||||
18 | # %run example-embed.py) |
|
18 | # %run example-embed.py) | |
19 |
|
19 | |||
20 | from IPython.terminal.prompts import Prompts, Token |
|
20 | from IPython.terminal.prompts import Prompts, Token | |
|
21 | from traitlets.config.loader import Config | |||
21 |
|
22 | |||
22 | class CustomPrompt(Prompts): |
|
23 | class CustomPrompt(Prompts): | |
23 |
|
24 | |||
24 |
def in_prompt_tokens(self |
|
25 | def in_prompt_tokens(self): | |
25 |
|
26 | |||
26 | return [ |
|
27 | return [ | |
27 | (Token.Prompt, 'In <'), |
|
28 | (Token.Prompt, 'In <'), | |
28 | (Token.PromptNum, str(self.shell.execution_count)), |
|
29 | (Token.PromptNum, str(self.shell.execution_count)), | |
29 | (Token.Prompt, '>: '), |
|
30 | (Token.Prompt, '>: '), | |
30 | ] |
|
31 | ] | |
31 |
|
32 | |||
32 | def out_prompt_tokens(self): |
|
33 | def out_prompt_tokens(self): | |
33 | return [ |
|
34 | return [ | |
34 | (Token.OutPrompt, 'Out<'), |
|
35 | (Token.OutPrompt, 'Out<'), | |
35 | (Token.OutPromptNum, str(self.shell.execution_count)), |
|
36 | (Token.OutPromptNum, str(self.shell.execution_count)), | |
36 | (Token.OutPrompt, '>: '), |
|
37 | (Token.OutPrompt, '>: '), | |
37 | ] |
|
38 | ] | |
38 |
|
39 | |||
39 |
|
40 | |||
40 | from traitlets.config.loader import Config |
|
|||
41 | try: |
|
41 | try: | |
42 | get_ipython |
|
42 | get_ipython | |
43 | except NameError: |
|
43 | except NameError: |
@@ -6,9 +6,12 b' import os' | |||||
6 |
|
6 | |||
7 | class MyPrompt(Prompts): |
|
7 | class MyPrompt(Prompts): | |
8 |
|
8 | |||
9 |
|
|
9 | def in_prompt_tokens(self): | |
10 | return [(Token, os.getcwd()), |
|
10 | return [ | |
11 |
|
|
11 | (Token, os.getcwd()), | |
|
12 | (Token.Prompt, ">>>") | |||
|
13 | ] | |||
|
14 | ||||
12 |
|
15 | |||
13 | def load_ipython_extension(shell): |
|
16 | def load_ipython_extension(shell): | |
14 | new_prompts = MyPrompt(shell) |
|
17 | new_prompts = MyPrompt(shell) | |
@@ -20,7 +23,3 b' def unload_ipython_extension(shell):' | |||||
20 | print("cannot unload") |
|
23 | print("cannot unload") | |
21 | else: |
|
24 | else: | |
22 | shell.prompts = shell.prompts.old_prompts |
|
25 | shell.prompts = shell.prompts.old_prompts | |
23 |
|
||||
24 |
|
||||
25 |
|
||||
26 |
|
General Comments 0
You need to be logged in to leave comments.
Login now