##// END OF EJS Templates
Backport PR #6653: Fix IPython.utils.ansispan() to ignore stray [0m...
Min RK -
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,11 +290,19 b' IPython.utils = (function (IPython) {'
290 function ansispan(str) {
290 function ansispan(str) {
291 // ansispan function adapted from github.com/mmalecki/ansispan (MIT License)
291 // ansispan function adapted from github.com/mmalecki/ansispan (MIT License)
292 // regular ansi escapes (using the table above)
292 // regular ansi escapes (using the table above)
293 var is_open = false
293 return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) {
294 return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) {
294 if (!pattern) {
295 if (!pattern) {
295 // [(01|22|39|)m close spans
296 // [(01|22|39|)m close spans
297 if (is_open) {
298 is_open = false;
296 return "</span>";
299 return "</span>";
300 } else {
301 return "";
297 }
302 }
303 } else {
304 is_open = true;
305
298 // consume sequence of color escapes
306 // consume sequence of color escapes
299 var numbers = pattern.match(/\d+/g);
307 var numbers = pattern.match(/\d+/g);
300 var attrs = {};
308 var attrs = {};
@@ -308,6 +316,7 b' IPython.utils = (function (IPython) {'
308 span = span + " " + attr + '="' + attrs[attr] + '"';
316 span = span + " " + attr + '="' + attrs[attr] + '"';
309 }
317 }
310 return span + ">";
318 return span + ">";
319 }
311 });
320 });
312 };
321 };
313
322
@@ -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: brown;}
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
@@ -31,7 +31,7 b' div.traceback-wrapper{text-align:left;max-width:800px;margin:auto}'
31 .ansiblack{color:#000}
31 .ansiblack{color:#000}
32 .ansired{color:#8b0000}
32 .ansired{color:#8b0000}
33 .ansigreen{color:#006400}
33 .ansigreen{color:#006400}
34 .ansiyellow{color:#a52a2a}
34 .ansiyellow{color:#c4a000}
35 .ansiblue{color:#00008b}
35 .ansiblue{color:#00008b}
36 .ansipurple{color:#9400d3}
36 .ansipurple{color:#9400d3}
37 .ansicyan{color:#4682b4}
37 .ansicyan{color:#4682b4}
@@ -1336,7 +1336,7 b' input.engine_num_input{width:60px}'
1336 .ansiblack{color:#000}
1336 .ansiblack{color:#000}
1337 .ansired{color:#8b0000}
1337 .ansired{color:#8b0000}
1338 .ansigreen{color:#006400}
1338 .ansigreen{color:#006400}
1339 .ansiyellow{color:#a52a2a}
1339 .ansiyellow{color:#c4a000}
1340 .ansiblue{color:#00008b}
1340 .ansiblue{color:#00008b}
1341 .ansipurple{color:#9400d3}
1341 .ansipurple{color:#9400d3}
1342 .ansicyan{color:#4682b4}
1342 .ansicyan{color:#4682b4}
General Comments 0
You need to be logged in to leave comments. Login now