##// 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 if (json.stream == undefined){
623 if (json.stream == undefined){
624 json.stream = 'stdout';
624 json.stream = 'stdout';
625 }
625 }
626 if (!utils.fixConsole(json.text)){
626
627 // fixConsole gives nothing (empty string, \r, etc.)
627 var text = utils.fixConsole(json.text);
628 // so don't append any elements, which might add undesirable space
629 return;
630 }
631 var subclass = "output_"+json.stream;
628 var subclass = "output_"+json.stream;
632 if (this.outputs.length > 0){
629 if (this.outputs.length > 0){
633 // have at least one output to consider
630 // have at least one output to consider
@@ -636,15 +633,22 b' var IPython = (function (IPython) {'
636 // latest output was in the same stream,
633 // latest output was in the same stream,
637 // so append directly into its pre tag
634 // so append directly into its pre tag
638 // escape ANSI & HTML specials:
635 // escape ANSI & HTML specials:
639 var text = utils.fixConsole(json.text);
636 pre = this.element.find('div.'+subclass).last().find('pre');
640 this.element.find('div.'+subclass).last().find('pre').append(text);
637 text = utils.fixCarriageReturn(pre.text() + text);
638 pre.text(text);
641 return;
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 // If we got here, attach a new div
649 // If we got here, attach a new div
646 var toinsert = this.create_output_area();
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 this.element.find('div.output').append(toinsert);
652 this.element.find('div.output').append(toinsert);
649 };
653 };
650
654
@@ -702,6 +706,7 b' var IPython = (function (IPython) {'
702 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
706 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
703 // escape ANSI & HTML specials in plaintext:
707 // escape ANSI & HTML specials in plaintext:
704 data = utils.fixConsole(data);
708 data = utils.fixConsole(data);
709 data = utils.fixCarriageReturn(data);
705 if (extra_class){
710 if (extra_class){
706 toinsert.addClass(extra_class);
711 toinsert.addClass(extra_class);
707 }
712 }
@@ -89,9 +89,9 b' var IPython = (function (IPython) {'
89
89
90 Pager.prototype.append_text = function (text) {
90 Pager.prototype.append_text = function (text) {
91 var toinsert = $("<div/>").addClass("output_area output_stream");
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 this.pager_element.append(toinsert);
93 this.pager_element.append(toinsert);
94 };
94 };
95
95
96
96
97 IPython.Pager = Pager;
97 IPython.Pager = Pager;
@@ -47,7 +47,7 b' IPython.utils = (function (IPython) {'
47 "37":"ansigrey", "01":"ansibold"
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 // classes listed in the above ansi_colormap object. The actual color used
51 // classes listed in the above ansi_colormap object. The actual color used
52 // are set in the css file.
52 // are set in the css file.
53 function fixConsole(txt) {
53 function fixConsole(txt) {
@@ -57,8 +57,6 b' IPython.utils = (function (IPython) {'
57 var cmds = [];
57 var cmds = [];
58 var opener = "";
58 var opener = "";
59 var closer = "";
59 var closer = "";
60 // \r does nothing, so shouldn't be included
61 txt = txt.replace('\r', '');
62 while (re.test(txt)) {
60 while (re.test(txt)) {
63 var cmds = txt.match(re)[1].split(";");
61 var cmds = txt.match(re)[1].split(";");
64 closer = opened?"</span>":"";
62 closer = opened?"</span>":"";
@@ -74,6 +72,16 b' IPython.utils = (function (IPython) {'
74 return txt;
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 grow = function(element) {
86 grow = function(element) {
79 // Grow the cell by hand. This is used upon reloading from JSON, when the
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 return {
103 return {
96 uuid : uuid,
104 uuid : uuid,
97 fixConsole : fixConsole,
105 fixConsole : fixConsole,
98 grow : grow
106 grow : grow,
107 fixCarriageReturn : fixCarriageReturn
99 };
108 };
100
109
101 }(IPython));
110 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now