##// END OF EJS Templates
Merge pull request #1659 from mdboom/notebook-carriage-return...
Min RK -
r6659:cb4d9d8d merge
parent child Browse files
Show More
@@ -623,11 +623,8 b' var IPython = (function (IPython) {'
623 623 if (json.stream == undefined){
624 624 json.stream = 'stdout';
625 625 }
626 if (!utils.fixConsole(json.text)){
627 // fixConsole gives nothing (empty string, \r, etc.)
628 // so don't append any elements, which might add undesirable space
629 return;
630 }
626
627 var text = utils.fixConsole(json.text);
631 628 var subclass = "output_"+json.stream;
632 629 if (this.outputs.length > 0){
633 630 // have at least one output to consider
@@ -636,15 +633,22 b' var IPython = (function (IPython) {'
636 633 // latest output was in the same stream,
637 634 // so append directly into its pre tag
638 635 // escape ANSI & HTML specials:
639 var text = utils.fixConsole(json.text);
640 this.element.find('div.'+subclass).last().find('pre').append(text);
636 pre = this.element.find('div.'+subclass).last().find('pre');
637 text = utils.fixCarriageReturn(pre.text() + text);
638 pre.text(text);
641 639 return;
642 640 }
643 641 }
644
642
643 if (!text.replace("\r", "")) {
644 // text is nothing (empty string, \r, etc.)
645 // so don't append any elements, which might add undesirable space
646 return;
647 }
648
645 649 // If we got here, attach a new div
646 650 var toinsert = this.create_output_area();
647 this.append_text(json.text, toinsert, "output_stream "+subclass);
651 this.append_text(text, toinsert, "output_stream "+subclass);
648 652 this.element.find('div.output').append(toinsert);
649 653 };
650 654
@@ -702,6 +706,7 b' var IPython = (function (IPython) {'
702 706 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
703 707 // escape ANSI & HTML specials in plaintext:
704 708 data = utils.fixConsole(data);
709 data = utils.fixCarriageReturn(data);
705 710 if (extra_class){
706 711 toinsert.addClass(extra_class);
707 712 }
@@ -89,9 +89,9 b' var IPython = (function (IPython) {'
89 89
90 90 Pager.prototype.append_text = function (text) {
91 91 var toinsert = $("<div/>").addClass("output_area output_stream");
92 toinsert.append($('<pre/>').html(utils.fixConsole(text)));
92 toinsert.append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
93 93 this.pager_element.append(toinsert);
94 };
94 };
95 95
96 96
97 97 IPython.Pager = Pager;
@@ -47,7 +47,7 b' IPython.utils = (function (IPython) {'
47 47 "37":"ansigrey", "01":"ansibold"
48 48 };
49 49
50 // Transform ANI color escape codes into HTML <span> tags with css
50 // Transform ANSI color escape codes into HTML <span> tags with css
51 51 // classes listed in the above ansi_colormap object. The actual color used
52 52 // are set in the css file.
53 53 function fixConsole(txt) {
@@ -57,8 +57,6 b' IPython.utils = (function (IPython) {'
57 57 var cmds = [];
58 58 var opener = "";
59 59 var closer = "";
60 // \r does nothing, so shouldn't be included
61 txt = txt.replace('\r', '');
62 60 while (re.test(txt)) {
63 61 var cmds = txt.match(re)[1].split(";");
64 62 closer = opened?"</span>":"";
@@ -74,6 +72,16 b' IPython.utils = (function (IPython) {'
74 72 return txt;
75 73 }
76 74
75 // Remove chunks that should be overridden by the effect of
76 // carriage return characters
77 function fixCarriageReturn(txt) {
78 tmp = txt;
79 do {
80 txt = tmp;
81 tmp = txt.replace(/^.*\r/gm, '');
82 } while (tmp.length < txt.length);
83 return txt;
84 }
77 85
78 86 grow = function(element) {
79 87 // Grow the cell by hand. This is used upon reloading from JSON, when the
@@ -95,7 +103,8 b' IPython.utils = (function (IPython) {'
95 103 return {
96 104 uuid : uuid,
97 105 fixConsole : fixConsole,
98 grow : grow
106 grow : grow,
107 fixCarriageReturn : fixCarriageReturn
99 108 };
100 109
101 110 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now