Show More
@@ -2,6 +2,7 b'' | |||
|
2 | 2 | |
|
3 | 3 | import os |
|
4 | 4 | import sys |
|
5 | import inspect | |
|
5 | 6 | from warnings import warn |
|
6 | 7 | from typing import Union as UnionType, Optional |
|
7 | 8 | |
@@ -65,8 +66,8 b' from .shortcuts.auto_suggest import (' | |||
|
65 | 66 | PTK3 = ptk_version.startswith('3.') |
|
66 | 67 | |
|
67 | 68 | |
|
68 |
class _NoStyle(Style): |
|
|
69 | ||
|
69 | class _NoStyle(Style): | |
|
70 | pass | |
|
70 | 71 | |
|
71 | 72 | |
|
72 | 73 | _style_overrides_light_bg = { |
@@ -83,6 +84,20 b' _style_overrides_linux = {' | |||
|
83 | 84 | Token.OutPromptNum: '#ansired bold', |
|
84 | 85 | } |
|
85 | 86 | |
|
87 | ||
|
88 | def _backward_compat_continuation_prompt_tokens(method, width: int, *, lineno: int): | |
|
89 | """ | |
|
90 | Sagemath use custom prompt and we broke them in 8.19. | |
|
91 | """ | |
|
92 | sig = inspect.signature(method) | |
|
93 | if "lineno" in inspect.signature(method).parameters or any( | |
|
94 | [p.kind == p.VAR_KEYWORD for p in sig.parameters.values()] | |
|
95 | ): | |
|
96 | return method(width, lineno=lineno) | |
|
97 | else: | |
|
98 | return method(width) | |
|
99 | ||
|
100 | ||
|
86 | 101 | def get_default_editor(): |
|
87 | 102 | try: |
|
88 | 103 | return os.environ['EDITOR'] |
@@ -762,7 +777,9 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
762 | 777 | "message": get_message, |
|
763 | 778 | "prompt_continuation": ( |
|
764 | 779 | lambda width, lineno, is_soft_wrap: PygmentsTokens( |
|
765 |
|
|
|
780 | _backward_compat_continuation_prompt_tokens( | |
|
781 | self.prompts.continuation_prompt_tokens, width, lineno=lineno | |
|
782 | ) | |
|
766 | 783 | ) |
|
767 | 784 | ), |
|
768 | 785 | "multiline": True, |
@@ -33,8 +33,8 b' which defines the defaults. The required interface is like this:' | |||
|
33 | 33 | Prompt style definition. *shell* is a reference to the |
|
34 | 34 | :class:`~.TerminalInteractiveShell` instance. |
|
35 | 35 | |
|
36 |
.. method:: in_prompt_tokens( |
|
|
37 |
continuation_prompt_tokens(self, |
|
|
36 | .. method:: in_prompt_tokens() | |
|
37 | continuation_prompt_tokens(self, width=None) | |
|
38 | 38 | rewrite_prompt_tokens() |
|
39 | 39 | out_prompt_tokens() |
|
40 | 40 | |
@@ -43,8 +43,6 b' which defines the defaults. The required interface is like this:' | |||
|
43 | 43 | For continuation prompts, *width* is an integer representing the width of |
|
44 | 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 | 47 | Here is an example Prompt class that will show the current working directory |
|
50 | 48 | in the input prompt: |
@@ -55,7 +53,7 b' in the input prompt:' | |||
|
55 | 53 | import os |
|
56 | 54 | |
|
57 | 55 | class MyPrompt(Prompts): |
|
58 |
def in_prompt_tokens(self |
|
|
56 | def in_prompt_tokens(self): | |
|
59 | 57 | return [(Token, os.getcwd()), |
|
60 | 58 | (Token.Prompt, ' >>>')] |
|
61 | 59 |
@@ -18,26 +18,26 b' The code in this file is deliberately extra-verbose, meant for learning."""' | |||
|
18 | 18 | # %run example-embed.py) |
|
19 | 19 | |
|
20 | 20 | from IPython.terminal.prompts import Prompts, Token |
|
21 | from traitlets.config.loader import Config | |
|
21 | 22 | |
|
22 | 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 | 28 | (Token.Prompt, 'In <'), |
|
28 | 29 | (Token.PromptNum, str(self.shell.execution_count)), |
|
29 | 30 | (Token.Prompt, '>: '), |
|
30 | 31 | ] |
|
31 | 32 | |
|
32 | 33 | def out_prompt_tokens(self): |
|
33 | return [ | |
|
34 | return [ | |
|
34 | 35 | (Token.OutPrompt, 'Out<'), |
|
35 | 36 | (Token.OutPromptNum, str(self.shell.execution_count)), |
|
36 | 37 | (Token.OutPrompt, '>: '), |
|
37 | 38 | ] |
|
38 | 39 | |
|
39 | 40 | |
|
40 | from traitlets.config.loader import Config | |
|
41 | 41 | try: |
|
42 | 42 | get_ipython |
|
43 | 43 | except NameError: |
@@ -6,9 +6,9 b' import os' | |||
|
6 | 6 | |
|
7 | 7 | class MyPrompt(Prompts): |
|
8 | 8 | |
|
9 |
|
|
|
10 |
|
|
|
11 | (Token.Prompt, '>>>')] | |
|
9 | def in_prompt_tokens(self): | |
|
10 | return [(Token, os.getcwd()), (Token.Prompt, ">>>")] | |
|
11 | ||
|
12 | 12 | |
|
13 | 13 | def load_ipython_extension(shell): |
|
14 | 14 | new_prompts = MyPrompt(shell) |
@@ -20,7 +20,3 b' def unload_ipython_extension(shell):' | |||
|
20 | 20 | print("cannot unload") |
|
21 | 21 | else: |
|
22 | 22 | shell.prompts = shell.prompts.old_prompts |
|
23 | ||
|
24 | ||
|
25 | ||
|
26 |
General Comments 0
You need to be logged in to leave comments.
Login now