Send unicode strings or FmtStr to Repl stdout or stderr Must be able to handle FmtStrs because interpreter pass in tracebacks already formatted.
(self, output)
| 1366 | return "\n".join(self.buffer + [self.current_line]) |
| 1367 | |
| 1368 | def send_to_stdouterr(self, output): |
| 1369 | """Send unicode strings or FmtStr to Repl stdout or stderr |
| 1370 | |
| 1371 | Must be able to handle FmtStrs because interpreter pass in |
| 1372 | tracebacks already formatted.""" |
| 1373 | lines = output.split("\n") |
| 1374 | logger.debug("display_lines: %r", self.display_lines) |
| 1375 | self.current_stdouterr_line += lines[0] |
| 1376 | if len(lines) > 1: |
| 1377 | self.display_lines.extend( |
| 1378 | paint.display_linize( |
| 1379 | self.current_stdouterr_line, self.width, blank_line=True |
| 1380 | ) |
| 1381 | ) |
| 1382 | self.display_lines.extend( |
| 1383 | sum( |
| 1384 | ( |
| 1385 | paint.display_linize(line, self.width, blank_line=True) |
| 1386 | for line in lines[1:-1] |
| 1387 | ), |
| 1388 | [], |
| 1389 | ) |
| 1390 | ) |
| 1391 | # These can be FmtStrs, but self.all_logical_lines only wants strings |
| 1392 | for line in itertools.chain( |
| 1393 | (self.current_stdouterr_line,), lines[1:-1] |
| 1394 | ): |
| 1395 | if isinstance(line, FmtStr): |
| 1396 | self.all_logical_lines.append((line.s, LineType.OUTPUT)) |
| 1397 | else: |
| 1398 | self.all_logical_lines.append((line, LineType.OUTPUT)) |
| 1399 | |
| 1400 | self.current_stdouterr_line = lines[-1] |
| 1401 | logger.debug("display_lines: %r", self.display_lines) |
| 1402 | |
| 1403 | def send_to_stdin(self, line): |
| 1404 | if line.endswith("\n"): |