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