##// END OF EJS Templates
Simplify color definition....
Matthias Bussonnier -
Show More
@@ -190,22 +190,28 b' class Alias(object):'
190 #-----------------------------------------------------------------------------
190 #-----------------------------------------------------------------------------
191
191
192 class AliasManager(Configurable):
192 class AliasManager(Configurable):
193
193 default_aliases: List = List(default_aliases()).tag(config=True)
194 default_aliases = List(default_aliases()).tag(config=True)
194 user_aliases: List = List(default_value=[]).tag(config=True)
195 user_aliases = List(default_value=[]).tag(config=True)
195 shell = Instance(
196 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
196 "IPython.core.interactiveshell.InteractiveShellABC", allow_none=True
197 )
197
198
198 def __init__(self, shell=None, **kwargs):
199 def __init__(self, shell=None, **kwargs):
199 super(AliasManager, self).__init__(shell=shell, **kwargs)
200 super(AliasManager, self).__init__(shell=shell, **kwargs)
200 # For convenient access
201 # For convenient access
201 self.linemagics = self.shell.magics_manager.magics['line']
202 if self.shell is not None:
202 self.init_aliases()
203 self.linemagics = self.shell.magics_manager.magics["line"]
204 self.init_aliases()
203
205
204 def init_aliases(self):
206 def init_aliases(self):
205 # Load default & user aliases
207 # Load default & user aliases
206 for name, cmd in self.default_aliases + self.user_aliases:
208 for name, cmd in self.default_aliases + self.user_aliases:
207 if cmd.startswith('ls ') and self.shell.colors == 'NoColor':
209 if (
208 cmd = cmd.replace(' --color', '')
210 cmd.startswith("ls ")
211 and self.shell is not None
212 and self.shell.colors == "NoColor"
213 ):
214 cmd = cmd.replace(" --color", "")
209 self.soft_define_alias(name, cmd)
215 self.soft_define_alias(name, cmd)
210
216
211 @property
217 @property
@@ -246,7 +252,7 b' class AliasManager(Configurable):'
246 raise ValueError('%s is not an alias' % name)
252 raise ValueError('%s is not an alias' % name)
247
253
248 def clear_aliases(self):
254 def clear_aliases(self):
249 for name, cmd in self.aliases:
255 for name, _ in self.aliases:
250 self.undefine_alias(name)
256 self.undefine_alias(name)
251
257
252 def retrieve_alias(self, name):
258 def retrieve_alias(self, name):
@@ -42,118 +42,128 b' def exception_colors():'
42 ex_colors = ColorSchemeTable()
42 ex_colors = ColorSchemeTable()
43
43
44 # Populate it with color schemes
44 # Populate it with color schemes
45 C = TermColors # shorthand and local lookup
45 C = TermColors # shorthand and local lookup
46 ex_colors.add_scheme(ColorScheme(
46 ex_colors.add_scheme(
47 'NoColor',
47 ColorScheme(
48 # The color to be used for the top line
48 "NoColor",
49 topline = C.NoColor,
49 {
50
50 # The color to be used for the top line
51 # The colors to be used in the traceback
51 "topline": C.NoColor,
52 filename = C.NoColor,
52
53 lineno = C.NoColor,
53 # The colors to be used in the traceback
54 name = C.NoColor,
54 "filename": C.NoColor,
55 vName = C.NoColor,
55 "lineno": C.NoColor,
56 val = C.NoColor,
56 "name": C.NoColor,
57 em = C.NoColor,
57 "vName": C.NoColor,
58
58 "val": C.NoColor,
59 # Emphasized colors for the last frame of the traceback
59 "em": C.NoColor,
60 normalEm = C.NoColor,
60
61 filenameEm = C.NoColor,
61 # Emphasized colors for the last frame of the traceback
62 linenoEm = C.NoColor,
62 "normalEm": C.NoColor,
63 nameEm = C.NoColor,
63 "filenameEm": C.NoColor,
64 valEm = C.NoColor,
64 "linenoEm": C.NoColor,
65
65 "nameEm": C.NoColor,
66 # Colors for printing the exception
66 "valEm": C.NoColor,
67 excName = C.NoColor,
67
68 line = C.NoColor,
68 # Colors for printing the exception
69 caret = C.NoColor,
69 "excName": C.NoColor,
70 Normal = C.NoColor
70 "line": C.NoColor,
71 ))
71 "caret": C.NoColor,
72 "Normal": C.NoColor,
73 },
74 )
75 )
72
76
73 # make some schemes as instances so we can copy them for modification easily
77 # make some schemes as instances so we can copy them for modification easily
74 ex_colors.add_scheme(ColorScheme(
78 ex_colors.add_scheme(
75 'Linux',
79 ColorScheme(
76 # The color to be used for the top line
80 "Linux",
77 topline = C.LightRed,
81 {
78
82 # The color to be used for the top line
79 # The colors to be used in the traceback
83 "topline": C.LightRed,
80 filename = C.Green,
84 # The colors to be used in the traceback
81 lineno = C.Green,
85 "filename": C.Green,
82 name = C.Purple,
86 "lineno": C.Green,
83 vName = C.Cyan,
87 "name": C.Purple,
84 val = C.Green,
88 "vName": C.Cyan,
85 em = C.LightCyan,
89 "val": C.Green,
86
90 "em": C.LightCyan,
87 # Emphasized colors for the last frame of the traceback
91 # Emphasized colors for the last frame of the traceback
88 normalEm = C.LightCyan,
92 "normalEm": C.LightCyan,
89 filenameEm = C.LightGreen,
93 "filenameEm": C.LightGreen,
90 linenoEm = C.LightGreen,
94 "linenoEm": C.LightGreen,
91 nameEm = C.LightPurple,
95 "nameEm": C.LightPurple,
92 valEm = C.LightBlue,
96 "valEm": C.LightBlue,
93
97 # Colors for printing the exception
94 # Colors for printing the exception
98 "excName": C.LightRed,
95 excName = C.LightRed,
99 "line": C.Yellow,
96 line = C.Yellow,
100 "caret": C.White,
97 caret = C.White,
101 "Normal": C.Normal,
98 Normal = C.Normal
102 },
99 ))
103 )
104 )
100
105
101 # For light backgrounds, swap dark/light colors
106 # For light backgrounds, swap dark/light colors
102 ex_colors.add_scheme(ColorScheme(
107 ex_colors.add_scheme(
103 'LightBG',
108 ColorScheme(
104 # The color to be used for the top line
109 "LightBG",
105 topline = C.Red,
110 {
106
111 # The color to be used for the top line
107 # The colors to be used in the traceback
112 "topline": C.Red,
108 filename = C.LightGreen,
113
109 lineno = C.LightGreen,
114 # The colors to be used in the traceback
110 name = C.LightPurple,
115 "filename": C.LightGreen,
111 vName = C.Cyan,
116 "lineno": C.LightGreen,
112 val = C.LightGreen,
117 "name": C.LightPurple,
113 em = C.Cyan,
118 "vName": C.Cyan,
114
119 "val": C.LightGreen,
115 # Emphasized colors for the last frame of the traceback
120 "em": C.Cyan,
116 normalEm = C.Cyan,
121
117 filenameEm = C.Green,
122 # Emphasized colors for the last frame of the traceback
118 linenoEm = C.Green,
123 "normalEm": C.Cyan,
119 nameEm = C.Purple,
124 "filenameEm": C.Green,
120 valEm = C.Blue,
125 "linenoEm": C.Green,
121
126 "nameEm": C.Purple,
122 # Colors for printing the exception
127 "valEm": C.Blue,
123 excName = C.Red,
128
124 #line = C.Brown, # brown often is displayed as yellow
129 # Colors for printing the exception
125 line = C.Red,
130 "excName": C.Red,
126 caret = C.Normal,
131 # "line": C.Brown, # brown often is displayed as yellow
127 Normal = C.Normal,
132 "line": C.Red,
128 ))
133 "caret": C.Normal,
129
134 "Normal": C.Normal,
130 ex_colors.add_scheme(ColorScheme(
135 },
131 'Neutral',
136 )
132 # The color to be used for the top line
137 )
133 topline = C.Red,
138
134
139 ex_colors.add_scheme(
135 # The colors to be used in the traceback
140 ColorScheme(
136 filename = C.LightGreen,
141 "Neutral",
137 lineno = C.LightGreen,
142 {
138 name = C.LightPurple,
143 # The color to be used for the top line
139 vName = C.Cyan,
144 "topline": C.Red,
140 val = C.LightGreen,
145 # The colors to be used in the traceback
141 em = C.Cyan,
146 "filename": C.LightGreen,
142
147 "lineno": C.LightGreen,
143 # Emphasized colors for the last frame of the traceback
148 "name": C.LightPurple,
144 normalEm = C.Cyan,
149 "vName": C.Cyan,
145 filenameEm = C.Green,
150 "val": C.LightGreen,
146 linenoEm = C.Green,
151 "em": C.Cyan,
147 nameEm = C.Purple,
152 # Emphasized colors for the last frame of the traceback
148 valEm = C.Blue,
153 "normalEm": C.Cyan,
149
154 "filenameEm": C.Green,
150 # Colors for printing the exception
155 "linenoEm": C.Green,
151 excName = C.Red,
156 "nameEm": C.Purple,
152 #line = C.Brown, # brown often is displayed as yellow
157 "valEm": C.Blue,
153 line = C.Red,
158 # Colors for printing the exception
154 caret = C.Normal,
159 "excName": C.Red,
155 Normal = C.Normal,
160 # line = C.Brown, # brown often is displayed as yellow
156 ))
161 "line": C.Red,
162 "caret": C.Normal,
163 "Normal": C.Normal,
164 },
165 )
166 )
157
167
158 # Hack: the 'neutral' colours are not very visible on a dark background on
168 # Hack: the 'neutral' colours are not very visible on a dark background on
159 # Windows. Since Windows command prompts have a dark background by default, and
169 # Windows. Since Windows command prompts have a dark background by default, and
@@ -10,8 +10,7 b' import sys'
10 from importlib import import_module, reload
10 from importlib import import_module, reload
11
11
12 from traitlets.config.configurable import Configurable
12 from traitlets.config.configurable import Configurable
13 from IPython.utils.path import ensure_dir_exists, compress_user
13 from IPython.utils.path import ensure_dir_exists
14 from IPython.utils.decorators import undoc
15 from traitlets import Instance
14 from traitlets import Instance
16
15
17
16
@@ -84,7 +83,7 b' class ExtensionManager(Configurable):'
84 if module_str in self.loaded:
83 if module_str in self.loaded:
85 return "already loaded"
84 return "already loaded"
86
85
87 from IPython.utils.syspathcontext import prepended_to_syspath
86 assert self.shell is not None
88
87
89 with self.shell.builtin_trap:
88 with self.shell.builtin_trap:
90 if module_str not in sys.modules:
89 if module_str not in sys.modules:
@@ -26,8 +26,7 b' from traitlets import List'
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
27
27
28 class PayloadManager(Configurable):
28 class PayloadManager(Configurable):
29
29 _payload: List = List([])
30 _payload = List([])
31
30
32 def write_payload(self, data, single=True):
31 def write_payload(self, data, single=True):
33 """Include or update the specified `data` payload in the PayloadManager.
32 """Include or update the specified `data` payload in the PayloadManager.
@@ -103,8 +103,8 b' class RichPromptDisplayHook(DisplayHook):'
103
103
104 if self.do_full_cache:
104 if self.do_full_cache:
105 tokens = self.shell.prompts.out_prompt_tokens()
105 tokens = self.shell.prompts.out_prompt_tokens()
106 prompt_txt = ''.join(s for t, s in tokens)
106 prompt_txt = "".join(s for _, s in tokens)
107 if prompt_txt and not prompt_txt.endswith('\n'):
107 if prompt_txt and not prompt_txt.endswith("\n"):
108 # Ask for a newline before multiline output
108 # Ask for a newline before multiline output
109 self.prompt_end_newline = False
109 self.prompt_end_newline = False
110
110
@@ -116,6 +116,7 b' class RichPromptDisplayHook(DisplayHook):'
116 sys.stdout.write(prompt_txt)
116 sys.stdout.write(prompt_txt)
117
117
118 def write_format_data(self, format_dict, md_dict=None) -> None:
118 def write_format_data(self, format_dict, md_dict=None) -> None:
119 assert self.shell is not None
119 if self.shell.mime_renderers:
120 if self.shell.mime_renderers:
120
121
121 for mime, handler in self.shell.mime_renderers.items():
122 for mime, handler in self.shell.mime_renderers.items():
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 """Tools for coloring text in ANSI terminals.
1 """Tools for coloring text in ANSI terminals.
3 """
2 """
4
3
@@ -9,12 +8,13 b''
9 # the file COPYING, distributed as part of this software.
8 # the file COPYING, distributed as part of this software.
10 #*****************************************************************************
9 #*****************************************************************************
11
10
12 __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable']
13
11
14 import os
12 import os
15
13
16 from IPython.utils.ipstruct import Struct
14 from IPython.utils.ipstruct import Struct
17
15
16 __all__ = ["TermColors", "InputTermColors", "ColorScheme", "ColorSchemeTable"]
17
18 color_templates = (
18 color_templates = (
19 # Dark colors
19 # Dark colors
20 ("Black" , "0;30"),
20 ("Black" , "0;30"),
@@ -110,6 +110,10 b' for name, value in color_templates:'
110
110
111 class ColorScheme:
111 class ColorScheme:
112 """Generic color scheme class. Just a name and a Struct."""
112 """Generic color scheme class. Just a name and a Struct."""
113
114 name: str
115 colors: Struct
116
113 def __init__(self,__scheme_name_,colordict=None,**colormap):
117 def __init__(self,__scheme_name_,colordict=None,**colormap):
114 self.name = __scheme_name_
118 self.name = __scheme_name_
115 if colordict is None:
119 if colordict is None:
@@ -3,7 +3,7 b' requires = ["setuptools >= 51.0.0"]'
3 build-backend = "setuptools.build_meta"
3 build-backend = "setuptools.build_meta"
4
4
5 [tool.mypy]
5 [tool.mypy]
6 python_version = 3.10
6 python_version = "3.10"
7 ignore_missing_imports = true
7 ignore_missing_imports = true
8 follow_imports = 'silent'
8 follow_imports = 'silent'
9 exclude = [
9 exclude = [
@@ -79,3 +79,6 b' ipdoctest_optionflags = ['
79 "ELLIPSIS"
79 "ELLIPSIS"
80 ]
80 ]
81 asyncio_mode = "strict"
81 asyncio_mode = "strict"
82
83 [tool.pyright]
84 pythonPlatform="All"
General Comments 0
You need to be logged in to leave comments. Login now