Skip to content

Commit f8e7b8e

Browse files
authored
Copy payloadpage.page from IPython (#1317)
1 parent 69d69b5 commit f8e7b8e

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
import warnings
2121
from pathlib import Path
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
@@ -541,10 +541,38 @@ def init_environment(self):
541541
env["PAGER"] = "cat"
542542
env["GIT_PAGER"] = "cat"
543543

544+
def payloadpage_page(self, strg, start=0, screen_lines=0, pager_cmd=None):
545+
"""Print a string, piping through a pager.
546+
547+
This version ignores the screen_lines and pager_cmd arguments and uses
548+
IPython's payload system instead.
549+
550+
Parameters
551+
----------
552+
strg : str or mime-dict
553+
Text to page, or a mime-type keyed dict of already formatted data.
554+
start : int
555+
Starting line at which to place the display.
556+
"""
557+
558+
# Some routines may auto-compute start offsets incorrectly and pass a
559+
# negative value. Offset to 0 for robustness.
560+
start = max(0, start)
561+
562+
data = strg if isinstance(strg, dict) else {"text/plain": strg}
563+
564+
payload = dict(
565+
source="page",
566+
data=data,
567+
start=start,
568+
)
569+
assert self.payload_manager is not None
570+
self.payload_manager.write_payload(payload)
571+
544572
def init_hooks(self):
545573
"""Initialize hooks."""
546574
super().init_hooks()
547-
self.set_hook("show_in_pager", page.as_hook(payloadpage.page), 99)
575+
self.set_hook("show_in_pager", page.as_hook(self.payloadpage_page), 99)
548576

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

0 commit comments

Comments
 (0)