|
20 | 20 | from pathlib import Path |
21 | 21 | from threading import local |
22 | 22 |
|
23 | | -from IPython.core import page, payloadpage |
| 23 | +from IPython.core import page |
24 | 24 | from IPython.core.autocall import ZMQExitAutocall |
25 | 25 | from IPython.core.displaypub import DisplayPublisher |
26 | 26 | from IPython.core.error import UsageError |
@@ -508,10 +508,38 @@ def init_environment(self): |
508 | 508 | env["PAGER"] = "cat" |
509 | 509 | env["GIT_PAGER"] = "cat" |
510 | 510 |
|
| 511 | + def payloadpage_page(self, strg, start=0, screen_lines=0, pager_cmd=None): |
| 512 | + """Print a string, piping through a pager. |
| 513 | +
|
| 514 | + This version ignores the screen_lines and pager_cmd arguments and uses |
| 515 | + IPython's payload system instead. |
| 516 | +
|
| 517 | + Parameters |
| 518 | + ---------- |
| 519 | + strg : str or mime-dict |
| 520 | + Text to page, or a mime-type keyed dict of already formatted data. |
| 521 | + start : int |
| 522 | + Starting line at which to place the display. |
| 523 | + """ |
| 524 | + |
| 525 | + # Some routines may auto-compute start offsets incorrectly and pass a |
| 526 | + # negative value. Offset to 0 for robustness. |
| 527 | + start = max(0, start) |
| 528 | + |
| 529 | + data = strg if isinstance(strg, dict) else {"text/plain": strg} |
| 530 | + |
| 531 | + payload = dict( |
| 532 | + source="page", |
| 533 | + data=data, |
| 534 | + start=start, |
| 535 | + ) |
| 536 | + assert self.payload_manager is not None |
| 537 | + self.payload_manager.write_payload(payload) |
| 538 | + |
511 | 539 | def init_hooks(self): |
512 | 540 | """Initialize hooks.""" |
513 | 541 | super().init_hooks() |
514 | | - self.set_hook("show_in_pager", page.as_hook(payloadpage.page), 99) |
| 542 | + self.set_hook("show_in_pager", page.as_hook(self.payloadpage_page), 99) |
515 | 543 |
|
516 | 544 | def init_data_pub(self): |
517 | 545 | """Delay datapub init until request, for deprecation warnings""" |
|
0 commit comments