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 | }); |
@@ -285,27 +285,36 b' define([' | |||||
285 | function ansispan(str) { |
|
285 | function ansispan(str) { | |
286 | // ansispan function adapted from github.com/mmalecki/ansispan (MIT License) |
|
286 | // ansispan function adapted from github.com/mmalecki/ansispan (MIT License) | |
287 | // regular ansi escapes (using the table above) |
|
287 | // regular ansi escapes (using the table above) | |
|
288 | var is_open = false | |||
288 | return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) { |
|
289 | return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) { | |
289 | if (!pattern) { |
|
290 | if (!pattern) { | |
290 | // [(01|22|39|)m close spans |
|
291 | // [(01|22|39|)m close spans | |
291 |
|
|
292 | if (is_open) { | |
292 | } |
|
293 | is_open = false; | |
293 | // consume sequence of color escapes |
|
294 | return "</span>"; | |
294 | var numbers = pattern.match(/\d+/g); |
|
295 | } else { | |
295 | var attrs = {}; |
|
296 | return ""; | |
296 | while (numbers.length > 0) { |
|
297 | } | |
297 | _process_numbers(attrs, numbers); |
|
298 | } else { | |
298 | } |
|
299 | is_open = true; | |
299 |
|
300 | |||
300 | var span = "<span "; |
|
301 | // consume sequence of color escapes | |
301 | for (var attr in attrs) { |
|
302 | var numbers = pattern.match(/\d+/g); | |
302 |
var |
|
303 | var attrs = {}; | |
303 | span = span + " " + attr + '="' + attrs[attr] + '"'; |
|
304 | while (numbers.length > 0) { | |
|
305 | _process_numbers(attrs, numbers); | |||
|
306 | } | |||
|
307 | ||||
|
308 | var span = "<span "; | |||
|
309 | for (var attr in attrs) { | |||
|
310 | var value = attrs[attr]; | |||
|
311 | span = span + " " + attr + '="' + attrs[attr] + '"'; | |||
|
312 | } | |||
|
313 | return span + ">"; | |||
304 | } |
|
314 | } | |
305 | return span + ">"; |
|
|||
306 | }); |
|
315 | }); | |
307 | }; |
|
316 | }; | |
308 |
|
317 | |||
309 | // Transform ANSI color escape codes into HTML <span> tags with css |
|
318 | // Transform ANSI color escape codes into HTML <span> tags with css | |
310 | // classes listed in the above ansi_colormap object. The actual color used |
|
319 | // classes listed in the above ansi_colormap object. The actual color used | |
311 | // are set in the css file. |
|
320 | // are set in the css file. |
@@ -1,13 +1,12 b'' | |||||
1 | /* CSS font colors for translated ANSI colors. */ |
|
1 | /* CSS font colors for translated ANSI colors. */ | |
2 |
|
2 | |||
3 |
|
||||
4 | .ansibold {font-weight: bold;} |
|
3 | .ansibold {font-weight: bold;} | |
5 |
|
4 | |||
6 | /* use dark versions for foreground, to improve visibility */ |
|
5 | /* use dark versions for foreground, to improve visibility */ | |
7 | .ansiblack {color: black;} |
|
6 | .ansiblack {color: black;} | |
8 | .ansired {color: darkred;} |
|
7 | .ansired {color: darkred;} | |
9 | .ansigreen {color: darkgreen;} |
|
8 | .ansigreen {color: darkgreen;} | |
10 |
.ansiyellow {color: |
|
9 | .ansiyellow {color: #c4a000;} | |
11 | .ansiblue {color: darkblue;} |
|
10 | .ansiblue {color: darkblue;} | |
12 | .ansipurple {color: darkviolet;} |
|
11 | .ansipurple {color: darkviolet;} | |
13 | .ansicyan {color: steelblue;} |
|
12 | .ansicyan {color: steelblue;} | |
@@ -22,4 +21,3 b'' | |||||
22 | .ansibgpurple {background-color: magenta;} |
|
21 | .ansibgpurple {background-color: magenta;} | |
23 | .ansibgcyan {background-color: cyan;} |
|
22 | .ansibgcyan {background-color: cyan;} | |
24 | .ansibggray {background-color: gray;} |
|
23 | .ansibggray {background-color: gray;} | |
25 |
|
General Comments 0
You need to be logged in to leave comments.
Login now