Show More
@@ -1,137 +1,137 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | Color schemes for exception handling code in IPython. |
|
3 | Color schemes for exception handling code in IPython. | |
4 | """ |
|
4 | """ | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu> |
|
7 | # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu> | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | # Distributed under the terms of the BSD License. The full license is in | |
10 | # the file COPYING, distributed as part of this software. |
|
10 | # the file COPYING, distributed as part of this software. | |
11 | #***************************************************************************** |
|
11 | #***************************************************************************** | |
12 |
|
12 | |||
13 | #**************************************************************************** |
|
13 | #**************************************************************************** | |
14 | # Required modules |
|
14 | # Required modules | |
15 | from IPython.utils.coloransi import ColorSchemeTable, TermColors, ColorScheme |
|
15 | from IPython.utils.coloransi import ColorSchemeTable, TermColors, ColorScheme | |
16 |
|
16 | |||
17 | def exception_colors(): |
|
17 | def exception_colors(): | |
18 | """Return a color table with fields for exception reporting. |
|
18 | """Return a color table with fields for exception reporting. | |
19 |
|
19 | |||
20 | The table is an instance of ColorSchemeTable with schemes added for |
|
20 | The table is an instance of ColorSchemeTable with schemes added for | |
21 | 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled |
|
21 | 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled | |
22 | in. |
|
22 | in. | |
23 |
|
23 | |||
24 | Examples: |
|
24 | Examples: | |
25 |
|
25 | |||
26 | >>> ec = exception_colors() |
|
26 | >>> ec = exception_colors() | |
27 | >>> ec.active_scheme_name |
|
27 | >>> ec.active_scheme_name | |
28 | '' |
|
28 | '' | |
29 | >>> print ec.active_colors |
|
29 | >>> print ec.active_colors | |
30 | None |
|
30 | None | |
31 |
|
31 | |||
32 | Now we activate a color scheme: |
|
32 | Now we activate a color scheme: | |
33 | >>> ec.set_active_scheme('NoColor') |
|
33 | >>> ec.set_active_scheme('NoColor') | |
34 | >>> ec.active_scheme_name |
|
34 | >>> ec.active_scheme_name | |
35 | 'NoColor' |
|
35 | 'NoColor' | |
36 | >>> ec.active_colors.keys() |
|
36 | >>> ec.active_colors.keys() | |
37 | ['em', 'caret', '__allownew', 'name', 'val', 'vName', 'Normal', 'normalEm', |
|
37 | ['em', 'filenameEm', 'excName', 'valEm', 'nameEm', 'line', 'topline', | |
38 | 'filename', 'linenoEm', 'excName', 'lineno', 'valEm', 'filenameEm', |
|
38 | 'name', 'caret', 'val', 'vName', 'Normal', 'filename', 'linenoEm', | |
39 | 'nameEm', 'line', 'topline'] |
|
39 | 'lineno', 'normalEm'] | |
40 | """ |
|
40 | """ | |
41 |
|
41 | |||
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(ColorScheme( | |
47 | 'NoColor', |
|
47 | 'NoColor', | |
48 | # The color to be used for the top line |
|
48 | # The color to be used for the top line | |
49 | topline = C.NoColor, |
|
49 | topline = C.NoColor, | |
50 |
|
50 | |||
51 | # The colors to be used in the traceback |
|
51 | # The colors to be used in the traceback | |
52 | filename = C.NoColor, |
|
52 | filename = C.NoColor, | |
53 | lineno = C.NoColor, |
|
53 | lineno = C.NoColor, | |
54 | name = C.NoColor, |
|
54 | name = C.NoColor, | |
55 | vName = C.NoColor, |
|
55 | vName = C.NoColor, | |
56 | val = C.NoColor, |
|
56 | val = C.NoColor, | |
57 | em = C.NoColor, |
|
57 | em = C.NoColor, | |
58 |
|
58 | |||
59 | # Emphasized colors for the last frame of the traceback |
|
59 | # Emphasized colors for the last frame of the traceback | |
60 | normalEm = C.NoColor, |
|
60 | normalEm = C.NoColor, | |
61 | filenameEm = C.NoColor, |
|
61 | filenameEm = C.NoColor, | |
62 | linenoEm = C.NoColor, |
|
62 | linenoEm = C.NoColor, | |
63 | nameEm = C.NoColor, |
|
63 | nameEm = C.NoColor, | |
64 | valEm = C.NoColor, |
|
64 | valEm = C.NoColor, | |
65 |
|
65 | |||
66 | # Colors for printing the exception |
|
66 | # Colors for printing the exception | |
67 | excName = C.NoColor, |
|
67 | excName = C.NoColor, | |
68 | line = C.NoColor, |
|
68 | line = C.NoColor, | |
69 | caret = C.NoColor, |
|
69 | caret = C.NoColor, | |
70 | Normal = C.NoColor |
|
70 | Normal = C.NoColor | |
71 | )) |
|
71 | )) | |
72 |
|
72 | |||
73 | # make some schemes as instances so we can copy them for modification easily |
|
73 | # make some schemes as instances so we can copy them for modification easily | |
74 | ex_colors.add_scheme(ColorScheme( |
|
74 | ex_colors.add_scheme(ColorScheme( | |
75 | 'Linux', |
|
75 | 'Linux', | |
76 | # The color to be used for the top line |
|
76 | # The color to be used for the top line | |
77 | topline = C.LightRed, |
|
77 | topline = C.LightRed, | |
78 |
|
78 | |||
79 | # The colors to be used in the traceback |
|
79 | # The colors to be used in the traceback | |
80 | filename = C.Green, |
|
80 | filename = C.Green, | |
81 | lineno = C.Green, |
|
81 | lineno = C.Green, | |
82 | name = C.Purple, |
|
82 | name = C.Purple, | |
83 | vName = C.Cyan, |
|
83 | vName = C.Cyan, | |
84 | val = C.Green, |
|
84 | val = C.Green, | |
85 | em = C.LightCyan, |
|
85 | em = C.LightCyan, | |
86 |
|
86 | |||
87 | # Emphasized colors for the last frame of the traceback |
|
87 | # Emphasized colors for the last frame of the traceback | |
88 | normalEm = C.LightCyan, |
|
88 | normalEm = C.LightCyan, | |
89 | filenameEm = C.LightGreen, |
|
89 | filenameEm = C.LightGreen, | |
90 | linenoEm = C.LightGreen, |
|
90 | linenoEm = C.LightGreen, | |
91 | nameEm = C.LightPurple, |
|
91 | nameEm = C.LightPurple, | |
92 | valEm = C.LightBlue, |
|
92 | valEm = C.LightBlue, | |
93 |
|
93 | |||
94 | # Colors for printing the exception |
|
94 | # Colors for printing the exception | |
95 | excName = C.LightRed, |
|
95 | excName = C.LightRed, | |
96 | line = C.Yellow, |
|
96 | line = C.Yellow, | |
97 | caret = C.White, |
|
97 | caret = C.White, | |
98 | Normal = C.Normal |
|
98 | Normal = C.Normal | |
99 | )) |
|
99 | )) | |
100 |
|
100 | |||
101 | # For light backgrounds, swap dark/light colors |
|
101 | # For light backgrounds, swap dark/light colors | |
102 | ex_colors.add_scheme(ColorScheme( |
|
102 | ex_colors.add_scheme(ColorScheme( | |
103 | 'LightBG', |
|
103 | 'LightBG', | |
104 | # The color to be used for the top line |
|
104 | # The color to be used for the top line | |
105 | topline = C.Red, |
|
105 | topline = C.Red, | |
106 |
|
106 | |||
107 | # The colors to be used in the traceback |
|
107 | # The colors to be used in the traceback | |
108 | filename = C.LightGreen, |
|
108 | filename = C.LightGreen, | |
109 | lineno = C.LightGreen, |
|
109 | lineno = C.LightGreen, | |
110 | name = C.LightPurple, |
|
110 | name = C.LightPurple, | |
111 | vName = C.Cyan, |
|
111 | vName = C.Cyan, | |
112 | val = C.LightGreen, |
|
112 | val = C.LightGreen, | |
113 | em = C.Cyan, |
|
113 | em = C.Cyan, | |
114 |
|
114 | |||
115 | # Emphasized colors for the last frame of the traceback |
|
115 | # Emphasized colors for the last frame of the traceback | |
116 | normalEm = C.Cyan, |
|
116 | normalEm = C.Cyan, | |
117 | filenameEm = C.Green, |
|
117 | filenameEm = C.Green, | |
118 | linenoEm = C.Green, |
|
118 | linenoEm = C.Green, | |
119 | nameEm = C.Purple, |
|
119 | nameEm = C.Purple, | |
120 | valEm = C.Blue, |
|
120 | valEm = C.Blue, | |
121 |
|
121 | |||
122 | # Colors for printing the exception |
|
122 | # Colors for printing the exception | |
123 | excName = C.Red, |
|
123 | excName = C.Red, | |
124 | #line = C.Brown, # brown often is displayed as yellow |
|
124 | #line = C.Brown, # brown often is displayed as yellow | |
125 | line = C.Red, |
|
125 | line = C.Red, | |
126 | caret = C.Normal, |
|
126 | caret = C.Normal, | |
127 | Normal = C.Normal, |
|
127 | Normal = C.Normal, | |
128 | )) |
|
128 | )) | |
129 |
|
129 | |||
130 | return ex_colors |
|
130 | return ex_colors | |
131 |
|
131 | |||
132 |
|
132 | |||
133 | # For backwards compatibility, keep around a single global object. Note that |
|
133 | # For backwards compatibility, keep around a single global object. Note that | |
134 | # this should NOT be used, the factory function should be used instead, since |
|
134 | # this should NOT be used, the factory function should be used instead, since | |
135 | # these objects are stateful and it's very easy to get strange bugs if any code |
|
135 | # these objects are stateful and it's very easy to get strange bugs if any code | |
136 | # modifies the module-level object's state. |
|
136 | # modifies the module-level object's state. | |
137 | ExceptionColors = exception_colors() |
|
137 | ExceptionColors = exception_colors() |
General Comments 0
You need to be logged in to leave comments.
Login now