From 7bcdc9c3807bef5210819e0604551ec6b893fd19 2014-10-20 16:19:00 From: Thomas Kluyver Date: 2014-10-20 16:19:00 Subject: [PATCH] Merge pull request #6653 from mattpap/fix_ansispan Fix IPython.utils.ansispan() to ignore stray [0m --- diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 8e25303..22261f3 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -285,27 +285,36 @@ define([ function ansispan(str) { // ansispan function adapted from github.com/mmalecki/ansispan (MIT License) // regular ansi escapes (using the table above) + var is_open = false return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) { if (!pattern) { // [(01|22|39|)m close spans - return ""; - } - // consume sequence of color escapes - var numbers = pattern.match(/\d+/g); - var attrs = {}; - while (numbers.length > 0) { - _process_numbers(attrs, numbers); - } - - var span = ""; + } else { + return ""; + } + } else { + is_open = true; + + // consume sequence of color escapes + var numbers = pattern.match(/\d+/g); + var attrs = {}; + while (numbers.length > 0) { + _process_numbers(attrs, numbers); + } + + var span = ""; } - return span + ">"; }); }; - + // Transform ANSI color escape codes into HTML tags with css // classes listed in the above ansi_colormap object. The actual color used // are set in the css file. diff --git a/IPython/html/static/notebook/less/ansicolors.less b/IPython/html/static/notebook/less/ansicolors.less index 05009fb..7f15301 100644 --- a/IPython/html/static/notebook/less/ansicolors.less +++ b/IPython/html/static/notebook/less/ansicolors.less @@ -1,13 +1,12 @@ /* CSS font colors for translated ANSI colors. */ - .ansibold {font-weight: bold;} /* use dark versions for foreground, to improve visibility */ .ansiblack {color: black;} .ansired {color: darkred;} .ansigreen {color: darkgreen;} -.ansiyellow {color: brown;} +.ansiyellow {color: #c4a000;} .ansiblue {color: darkblue;} .ansipurple {color: darkviolet;} .ansicyan {color: steelblue;} @@ -22,4 +21,3 @@ .ansibgpurple {background-color: magenta;} .ansibgcyan {background-color: cyan;} .ansibggray {background-color: gray;} - diff --git a/IPython/html/static/style/ipython.min.css b/IPython/html/static/style/ipython.min.css index 2ae3b60..fa2d6bf 100644 --- a/IPython/html/static/style/ipython.min.css +++ b/IPython/html/static/style/ipython.min.css @@ -294,7 +294,7 @@ div.traceback-wrapper { color: darkgreen; } .ansiyellow { - color: brown; + color: #c4a000; } .ansiblue { color: darkblue; diff --git a/IPython/html/static/style/style.min.css b/IPython/html/static/style/style.min.css index 2d85e86..8905b2f 100644 --- a/IPython/html/static/style/style.min.css +++ b/IPython/html/static/style/style.min.css @@ -8163,7 +8163,7 @@ input.engine_num_input { color: darkgreen; } .ansiyellow { - color: brown; + color: #c4a000; } .ansiblue { color: darkblue; diff --git a/IPython/html/tests/base/utils.js b/IPython/html/tests/base/utils.js new file mode 100644 index 0000000..fe5c878 --- /dev/null +++ b/IPython/html/tests/base/utils.js @@ -0,0 +1,23 @@ +casper.notebook_test(function () { + var input = [ + "\033[0m[\033[0minfo\033[0m] \033[0mtext\033[0m", + "\033[0m[\033[33mwarn\033[0m] \033[0m\tmore text\033[0m", + "\033[0m[\033[33mwarn\033[0m] \033[0m https://some/url/to/a/file.ext\033[0m", + "\033[0m[\033[31merror\033[0m] \033[0m\033[0m", + "\033[0m[\033[31merror\033[0m] \033[0m\teven more text\033[0m", + "\033[0m[\033[31merror\033[0m] \033[0m\t\tand more more text\033[0m"].join("\n"); + + var output = [ + "[info] text", + "[warn] \tmore text", + "[warn] https://some/url/to/a/file.ext", + "[error] ", + "[error] \teven more text", + "[error] \t\tand more more text"].join("\n"); + + var result = this.evaluate(function (input) { + return IPython.utils.fixConsole(input); + }, input); + + this.test.assertEquals(result, output, "IPython.utils.fixConsole() handles [0m correctly"); +});