Parcourir la source

Merge pull request #992 from afshin/payload-output

Send payload messages to output.
Steven Silvester il y a 8 ans
Parent
commit
615680d2e5

+ 1 - 1
src/console/index.css

@@ -79,6 +79,6 @@
 }
 
 
-.jp-ConsoleContent-content .jp-ConsoleContent-banner .jp-InputArea-prompt {
+.jp-ConsoleContent-content .jp-ConsoleContent-banner .jp-Cell-prompt {
   display: none;
 }

+ 22 - 17
src/notebook/notebook/actions.ts

@@ -958,23 +958,28 @@ namespace Private {
     let setNextInput = content.payload.filter(i => {
       return (i as any).source === 'set_next_input';
     })[0];
-    if (setNextInput) {
-      let text = (setNextInput as any).text;
-      let replace = (setNextInput as any).replace;
-      if (replace) {
-        child.model.source = text;
-      } else {
-        // Create a new code cell and add as the next cell.
-        let cell = parent.model.factory.createCodeCell();
-        cell.source = text;
-        let cells = parent.model.cells;
-        let i = cells.indexOf(child.model);
-        if (i === -1) {
-          cells.add(cell);
-        } else {
-          cells.insert(i + 1, cell);
-        }
-      }
+
+    if (!setNextInput) {
+      return;
+    }
+
+    let text = (setNextInput as any).text;
+    let replace = (setNextInput as any).replace;
+
+    if (replace) {
+      child.model.source = text;
+      return;
+    }
+
+    // Create a new code cell and add as the next cell.
+    let cell = parent.model.factory.createCodeCell();
+    cell.source = text;
+    let cells = parent.model.cells;
+    let i = cells.indexOf(child.model);
+    if (i === -1) {
+      cells.add(cell);
+    } else {
+      cells.insert(i + 1, cell);
     }
   }
 

+ 19 - 1
src/notebook/output-area/model.ts

@@ -98,7 +98,6 @@ class OutputAreaModel implements IDisposable {
       this.clear();
       this.clearNext = false;
     }
-
     if (output.output_type === 'input_request') {
       this.list.add(output);
     }
@@ -209,6 +208,25 @@ class OutputAreaModel implements IDisposable {
       // Handle the execute reply.
       future.onReply = (msg: KernelMessage.IExecuteReplyMsg) => {
         resolve(msg);
+        // API responses that contain a pager are special cased and their type
+        // is overriden from 'execute_reply' to 'display_data' in order to
+        // render output.
+        let content = msg.content as KernelMessage.IExecuteOkReply;
+        let payload = content && content.payload;
+        if (!payload || !payload.length) {
+          return;
+        }
+        let pages = payload.filter(i => (i as any).source === 'page');
+        if (!pages.length) {
+          return;
+        }
+        let page = JSON.parse(JSON.stringify(pages[0]));
+        let model: nbformat.IOutput = {
+          output_type: 'display_data',
+          data: (page as any).data as nbformat.MimeBundle,
+          metadata: {}
+        };
+        this.add(model);
       };
       // Handle stdin.
       future.onStdin = (msg: KernelMessage.IStdinMessage) => {

+ 7 - 7
src/notebook/output-area/widget.ts

@@ -737,27 +737,22 @@ class OutputWidget extends Widget {
       this.setOutput(child);
       return;
     }
-
     // Extract the data from the output and sanitize if necessary.
     let rendermime = this._rendermime;
     let bundle = this.getBundle(output as nbformat.IOutput);
     let data = this.convertBundle(bundle);
-
     // Clear the content.
     this.clear();
 
     // Bail if no data to display.
-    let msg = 'Did not find renderer for output mimebundle.';
     if (!data) {
-      console.log(msg);
+      console.warn('Did not find renderer for output mimebundle.');
       return;
     }
 
     // Create the output result area.
     let child = rendermime.render({ bundle: data, trusted, injector });
     if (!child) {
-      console.log(msg);
-      console.log(data);
       return;
     }
     this.setOutput(child);
@@ -782,6 +777,8 @@ class OutputWidget extends Widget {
     case 'error':
       child.addClass(ERROR_CLASS);
       break;
+    default:
+      break;
     }
   }
 
@@ -827,8 +824,9 @@ class OutputWidget extends Widget {
       bundle = (output as nbformat.IDisplayData).data;
       break;
     case 'stream':
+      let text = (output as nbformat.IStream).text;
       bundle = {
-        'application/vnd.jupyter.console-text': (output as nbformat.IStream).text
+        'application/vnd.jupyter.console-text': text
       };
       break;
     case 'error':
@@ -839,6 +837,8 @@ class OutputWidget extends Widget {
           `${out.ename}: ${out.evalue}`
       };
       break;
+    default:
+      break;
     }
     return bundle || {};
   }