From a9d9a8b72c5e6be1b3873c4467b6c4467e00aaca Mon Sep 17 00:00:00 2001 From: MinRK Date: Fri, 30 Sep 2011 17:08:04 -0700 Subject: [PATCH] support contiguous stream output in notebook Consecutive messages to stdout or stderr will not be split into separate divs, until a new message to different stream arrives. Appending will only occur when the latest output is the same as the new one. Interleaving messages will still result in multiple divs. --- .../html/notebook/static/js/codecell.js | 17 +++++++++++++++++ .../html/notebook/static/js/notebook.js | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 8a4da1bd5..9532eed8a 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -251,6 +251,23 @@ var IPython = (function (IPython) { CodeCell.prototype.append_stream = function (json) { + // temporary fix: if stream undefined (json file written prior to this patch), + // default to most likely stdout: + if (json.stream == undefined){ + json.stream = 'stdout'; + } + if (this.outputs.length > 0){ + // have at least one output to consider + var last = this.outputs[this.outputs.length-1]; + if (last.output_type == 'stream' && json.stream == last.stream){ + // latest output was in the same stream, + // so append directly into its pre tag + this.element.find('div.output_stream').last().find('pre').append(json.text); + return; + } + } + + // If we got here, attach a new div var toinsert = this.create_output_area(); this.append_text(json.text, toinsert); this.element.find('div.output').append(toinsert); diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index b84e3b830..f5fcdc859 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -710,7 +710,8 @@ var IPython = (function (IPython) { var json = {}; json.output_type = msg_type; if (msg_type === "stream") { - json.text = utils.fixConsole(content.data + '\n'); + json.text = utils.fixConsole(content.data); + json.stream = content.name; } else if (msg_type === "display_data") { json = this.convert_mime_types(json, content.data); } else if (msg_type === "pyout") {