|
2 | 2 |
|
3 | 3 | import asyncio
|
4 | 4 | import json
|
| 5 | +import os |
5 | 6 | import sys
|
6 | 7 | import traceback
|
7 | 8 | import typing as t
|
@@ -156,15 +157,39 @@ def _output_hook(ycell, outputs, msg) -> None:
|
156 | 157 | if msg_type in ("display_data", "stream", "execute_result", "error"):
|
157 | 158 | # FIXME support for version
|
158 | 159 | output = nbformat.v4.output_from_msg(msg)
|
159 |
| - get_logger().info("Got an output. %s", output) |
160 | 160 | outputs.append(output)
|
161 | 161 |
|
162 | 162 | if ycell is not None:
|
163 |
| - # FIXME support for 'stream' |
164 |
| - outputs = ycell["outputs"] |
165 |
| - with outputs.doc.transaction(): |
166 |
| - outputs.append(output) |
| 163 | + cell_outputs = ycell["outputs"] |
| 164 | + if msg_type == "stream": |
| 165 | + with cell_outputs.doc.transaction(): |
| 166 | + text = output["text"] |
| 167 | + |
| 168 | + # FIXME Logic is quite complex at https://github.com/jupyterlab/jupyterlab/blob/7ae2d436fc410b0cff51042a3350ba71f54f4445/packages/outputarea/src/model.ts#L518 |
| 169 | + if text.endswith((os.linesep, "\n")): |
| 170 | + text = text[:-1] |
| 171 | + |
| 172 | + if (not cell_outputs) or (cell_outputs[-1]["name"] != output["name"]): |
| 173 | + output["text"] = [text] |
| 174 | + cell_outputs.append(output) |
| 175 | + else: |
| 176 | + last_output = cell_outputs[-1] |
| 177 | + last_output["text"].append(text) |
| 178 | + cell_outputs[-1] = last_output |
| 179 | + else: |
| 180 | + with cell_outputs.doc.transaction(): |
| 181 | + cell_outputs.append(output) |
| 182 | + |
| 183 | + elif msg_type == "clear_output": |
| 184 | + # FIXME msg.content.wait - if true should clear at the next message |
| 185 | + outputs.clear() |
167 | 186 |
|
| 187 | + if ycell is not None: |
| 188 | + del ycell["outputs"][:] |
| 189 | + |
| 190 | + elif msg_type == "update_display_data": |
| 191 | + # FIXME |
| 192 | + ... |
168 | 193 |
|
169 | 194 | def _stdin_hook(msg) -> None:
|
170 | 195 | get_logger().info("Code snippet execution is waiting for an input.")
|
|
0 commit comments