Permalink
Browse files

Merge pull request #830 from minrk/stream

Several improvements to stdout/stderr handling and visual layout of cells.

Now stdout and stderr are kept contiguous (in a single div) if they are being written to continuously, and stderr is shown with a light red background to help distinguish from stdout.

Further, input cells now have a light gray background to help distinguish them from plain stdout areas.
  • Loading branch information...
2 parents 200a760 + c2e6e9a commit ca814f8519f04d9605434c4438a143ca9c7aeac5 @fperez fperez committed Oct 8, 2011
View
19 IPython/frontend/html/notebook/static/css/notebook.css
@@ -195,12 +195,17 @@ div.input {
page-break-inside: avoid;
}
+/* input_area and input_prompt must match in top border and margin for alignment */
div.input_area {
color: black;
+ border: 1px solid #ddd;
+ border-radius: 3px;
+ background: #fafafa;
}
div.input_prompt {
color: navy;
+ border-top: 1px solid transparent;
}
div.output {
@@ -227,12 +232,24 @@ div.output_subarea {
/* The rest of the output_* classes are for special styling of the different
output types */
-div.output_stream {
+/* all text output has this class: */
+div.output_text {
text-align: left;
color: black;
font-family: monospace;
}
+/* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
+div.output_stream {
+ padding-top: 0.0em;
+ padding-bottom: 0.0em;
+}
+div.output_stdout {
+}
+div.output_stderr {
+ background: #fdd; /* very light red background for stderr */
+}
+
div.output_latex {
text-align: left;
color: black;
View
29 IPython/frontend/html/notebook/static/js/codecell.js
@@ -251,8 +251,26 @@ 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';
+ }
+ var subclass = "output_"+json.stream;
+ 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.'+subclass).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.append_text(json.text, toinsert, "output_stream "+subclass);
this.element.find('div.output').append(toinsert);
};
@@ -292,8 +310,11 @@ var IPython = (function (IPython) {
}
- CodeCell.prototype.append_text = function (data, element) {
- var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_stream");
+ CodeCell.prototype.append_text = function (data, element, extra_class) {
+ var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
+ if (extra_class){
+ toinsert.addClass(extra_class);
+ }
toinsert.append($("<pre/>").html(data));
element.append(toinsert);
};
@@ -402,7 +423,7 @@ var IPython = (function (IPython) {
CodeCell.prototype.fromJSON = function (data) {
- // console.log('Import from JSON:', data);
+ console.log('Import from JSON:', data);
if (data.cell_type === 'code') {
if (data.input !== undefined) {
this.set_code(data.input);
View
3 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") {

0 comments on commit ca814f8

Please sign in to comment.