Show More
@@ -0,0 +1,23 b'' | |||
|
1 | casper.notebook_test(function () { | |
|
2 | var input = [ | |
|
3 | "\033[0m[\033[0minfo\033[0m] \033[0mtext\033[0m", | |
|
4 | "\033[0m[\033[33mwarn\033[0m] \033[0m\tmore text\033[0m", | |
|
5 | "\033[0m[\033[33mwarn\033[0m] \033[0m https://some/url/to/a/file.ext\033[0m", | |
|
6 | "\033[0m[\033[31merror\033[0m] \033[0m\033[0m", | |
|
7 | "\033[0m[\033[31merror\033[0m] \033[0m\teven more text\033[0m", | |
|
8 | "\033[0m[\033[31merror\033[0m] \033[0m\t\tand more more text\033[0m"].join("\n"); | |
|
9 | ||
|
10 | var output = [ | |
|
11 | "[info] text", | |
|
12 | "[<span class=\"ansiyellow\">warn</span>] \tmore text", | |
|
13 | "[<span class=\"ansiyellow\">warn</span>] https://some/url/to/a/file.ext", | |
|
14 | "[<span class=\"ansired\">error</span>] ", | |
|
15 | "[<span class=\"ansired\">error</span>] \teven more text", | |
|
16 | "[<span class=\"ansired\">error</span>] \t\tand more more text"].join("\n"); | |
|
17 | ||
|
18 | var result = this.evaluate(function (input) { | |
|
19 | return IPython.utils.fixConsole(input); | |
|
20 | }, input); | |
|
21 | ||
|
22 | this.test.assertEquals(result, output, "IPython.utils.fixConsole() handles [0m correctly"); | |
|
23 | }); |
@@ -290,27 +290,36 b' IPython.utils = (function (IPython) {' | |||
|
290 | 290 | function ansispan(str) { |
|
291 | 291 | // ansispan function adapted from github.com/mmalecki/ansispan (MIT License) |
|
292 | 292 | // regular ansi escapes (using the table above) |
|
293 | var is_open = false | |
|
293 | 294 | return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) { |
|
294 | 295 | if (!pattern) { |
|
295 | 296 | // [(01|22|39|)m close spans |
|
296 |
|
|
|
297 | } | |
|
298 | // consume sequence of color escapes | |
|
299 | var numbers = pattern.match(/\d+/g); | |
|
300 | var attrs = {}; | |
|
301 | while (numbers.length > 0) { | |
|
302 | _process_numbers(attrs, numbers); | |
|
303 | } | |
|
304 | ||
|
305 | var span = "<span "; | |
|
306 | for (var attr in attrs) { | |
|
307 |
var |
|
|
308 | span = span + " " + attr + '="' + attrs[attr] + '"'; | |
|
297 | if (is_open) { | |
|
298 | is_open = false; | |
|
299 | return "</span>"; | |
|
300 | } else { | |
|
301 | return ""; | |
|
302 | } | |
|
303 | } else { | |
|
304 | is_open = true; | |
|
305 | ||
|
306 | // consume sequence of color escapes | |
|
307 | var numbers = pattern.match(/\d+/g); | |
|
308 | var attrs = {}; | |
|
309 | while (numbers.length > 0) { | |
|
310 | _process_numbers(attrs, numbers); | |
|
311 | } | |
|
312 | ||
|
313 | var span = "<span "; | |
|
314 | for (var attr in attrs) { | |
|
315 | var value = attrs[attr]; | |
|
316 | span = span + " " + attr + '="' + attrs[attr] + '"'; | |
|
317 | } | |
|
318 | return span + ">"; | |
|
309 | 319 | } |
|
310 | return span + ">"; | |
|
311 | 320 | }); |
|
312 | 321 | }; |
|
313 | ||
|
322 | ||
|
314 | 323 | // Transform ANSI color escape codes into HTML <span> tags with css |
|
315 | 324 | // classes listed in the above ansi_colormap object. The actual color used |
|
316 | 325 | // are set in the css file. |
@@ -1,13 +1,12 b'' | |||
|
1 | 1 | /* CSS font colors for translated ANSI colors. */ |
|
2 | 2 | |
|
3 | ||
|
4 | 3 | .ansibold {font-weight: bold;} |
|
5 | 4 | |
|
6 | 5 | /* use dark versions for foreground, to improve visibility */ |
|
7 | 6 | .ansiblack {color: black;} |
|
8 | 7 | .ansired {color: darkred;} |
|
9 | 8 | .ansigreen {color: darkgreen;} |
|
10 |
.ansiyellow {color: |
|
|
9 | .ansiyellow {color: #c4a000;} | |
|
11 | 10 | .ansiblue {color: darkblue;} |
|
12 | 11 | .ansipurple {color: darkviolet;} |
|
13 | 12 | .ansicyan {color: steelblue;} |
@@ -22,4 +21,3 b'' | |||
|
22 | 21 | .ansibgpurple {background-color: magenta;} |
|
23 | 22 | .ansibgcyan {background-color: cyan;} |
|
24 | 23 | .ansibggray {background-color: gray;} |
|
25 |
@@ -31,7 +31,7 b' div.traceback-wrapper{text-align:left;max-width:800px;margin:auto}' | |||
|
31 | 31 | .ansiblack{color:#000} |
|
32 | 32 | .ansired{color:#8b0000} |
|
33 | 33 | .ansigreen{color:#006400} |
|
34 |
.ansiyellow{color:# |
|
|
34 | .ansiyellow{color:#c4a000} | |
|
35 | 35 | .ansiblue{color:#00008b} |
|
36 | 36 | .ansipurple{color:#9400d3} |
|
37 | 37 | .ansicyan{color:#4682b4} |
@@ -1336,7 +1336,7 b' input.engine_num_input{width:60px}' | |||
|
1336 | 1336 | .ansiblack{color:#000} |
|
1337 | 1337 | .ansired{color:#8b0000} |
|
1338 | 1338 | .ansigreen{color:#006400} |
|
1339 |
.ansiyellow{color:# |
|
|
1339 | .ansiyellow{color:#c4a000} | |
|
1340 | 1340 | .ansiblue{color:#00008b} |
|
1341 | 1341 | .ansipurple{color:#9400d3} |
|
1342 | 1342 | .ansicyan{color:#4682b4} |
General Comments 0
You need to be logged in to leave comments.
Login now