From e9216222df5e2a40ce528151f559e7699444da7a 2012-04-30 06:52:07 From: MinRK Date: 2012-04-30 06:52:07 Subject: [PATCH] revert PR #1659 caused critical problems with subprocess output. See `!ls` for an example. --- diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 673e02d..5119461 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -623,8 +623,11 @@ var IPython = (function (IPython) { if (json.stream == undefined){ json.stream = 'stdout'; } - - var text = utils.fixConsole(json.text); + if (!utils.fixConsole(json.text)){ + // fixConsole gives nothing (empty string, \r, etc.) + // so don't append any elements, which might add undesirable space + return; + } var subclass = "output_"+json.stream; if (this.outputs.length > 0){ // have at least one output to consider @@ -633,22 +636,15 @@ var IPython = (function (IPython) { // latest output was in the same stream, // so append directly into its pre tag // escape ANSI & HTML specials: - pre = this.element.find('div.'+subclass).last().find('pre'); - text = utils.fixCarriageReturn(pre.text() + text); - pre.text(text); + var text = utils.fixConsole(json.text); + this.element.find('div.'+subclass).last().find('pre').append(text); return; } } - - if (!text.replace("\r", "")) { - // text is nothing (empty string, \r, etc.) - // so don't append any elements, which might add undesirable space - return; - } - + // If we got here, attach a new div var toinsert = this.create_output_area(); - this.append_text(text, toinsert, "output_stream "+subclass); + this.append_text(json.text, toinsert, "output_stream "+subclass); this.element.find('div.output').append(toinsert); }; @@ -706,7 +702,6 @@ var IPython = (function (IPython) { var toinsert = $("
").addClass("box_flex1 output_subarea output_text"); // escape ANSI & HTML specials in plaintext: data = utils.fixConsole(data); - data = utils.fixCarriageReturn(data); if (extra_class){ toinsert.addClass(extra_class); } diff --git a/IPython/frontend/html/notebook/static/js/pager.js b/IPython/frontend/html/notebook/static/js/pager.js index ff79207..c3d4fcf 100644 --- a/IPython/frontend/html/notebook/static/js/pager.js +++ b/IPython/frontend/html/notebook/static/js/pager.js @@ -89,9 +89,9 @@ var IPython = (function (IPython) { Pager.prototype.append_text = function (text) { var toinsert = $("
").addClass("output_area output_stream"); - toinsert.append($('
').html(utils.fixCarriageReturn(utils.fixConsole(text))));
+        toinsert.append($('
').html(utils.fixConsole(text)));
         this.pager_element.append(toinsert);
-    };
+    };   
 
 
     IPython.Pager = Pager;
diff --git a/IPython/frontend/html/notebook/static/js/utils.js b/IPython/frontend/html/notebook/static/js/utils.js
index 5b68af4..5b1022b 100644
--- a/IPython/frontend/html/notebook/static/js/utils.js
+++ b/IPython/frontend/html/notebook/static/js/utils.js
@@ -47,7 +47,7 @@ IPython.utils = (function (IPython) {
         "37":"ansigrey", "01":"ansibold"
     };
 
-    // Transform ANSI color escape codes into HTML  tags with css
+    // Transform ANI 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.
     function fixConsole(txt) {
@@ -57,6 +57,8 @@ IPython.utils = (function (IPython) {
         var cmds = [];
         var opener = "";
         var closer = "";
+        // \r does nothing, so shouldn't be included
+        txt = txt.replace('\r', '');
         while (re.test(txt)) {
             var cmds = txt.match(re)[1].split(";");
             closer = opened?"":"";
@@ -72,16 +74,6 @@ IPython.utils = (function (IPython) {
         return txt;
     }
 
-    // Remove chunks that should be overridden by the effect of
-    // carriage return characters
-    function fixCarriageReturn(txt) {
-        tmp = txt;
-        do {
-            txt = tmp;
-            tmp = txt.replace(/^.*\r/gm, '');
-        } while (tmp.length < txt.length);
-        return txt;
-    }
 
     grow = function(element) {
         // Grow the cell by hand. This is used upon reloading from JSON, when the
@@ -103,8 +95,7 @@ IPython.utils = (function (IPython) {
     return {
         uuid : uuid,
         fixConsole : fixConsole,
-        grow : grow,
-        fixCarriageReturn : fixCarriageReturn
+        grow : grow
     };
 
 }(IPython));