Skip to content

Commit db1d474

Browse files
Carreauianthomas23
authored andcommitted
Copy payloadpage.page from IPython (ipython#1317)
1 parent accceab commit db1d474

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

ipykernel/zmqshell.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pathlib import Path
2121
from threading import local
2222

23-
from IPython.core import page, payloadpage
23+
from IPython.core import page
2424
from IPython.core.autocall import ZMQExitAutocall
2525
from IPython.core.displaypub import DisplayPublisher
2626
from IPython.core.error import UsageError
@@ -508,10 +508,38 @@ def init_environment(self):
508508
env["PAGER"] = "cat"
509509
env["GIT_PAGER"] = "cat"
510510

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+
511539
def init_hooks(self):
512540
"""Initialize hooks."""
513541
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)
515543

516544
def init_data_pub(self):
517545
"""Delay datapub init until request, for deprecation warnings"""

0 commit comments

Comments
 (0)