Skip to content

Commit 8d062c2

Browse files
committed
Copy payloadpage.page from IPython
IPykernel is the only user, and this will let us remove it from IPython. Closes #1304
1 parent f3f2a60 commit 8d062c2

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

ipykernel/zmqshell.py

Lines changed: 29 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,37 @@ 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+
self.shell.payload_manager.write_payload(payload)
570+
544571
def init_hooks(self):
545572
"""Initialize hooks."""
546573
super().init_hooks()
547-
self.set_hook("show_in_pager", page.as_hook(payloadpage.page), 99)
574+
self.set_hook("show_in_pager", page.as_hook(self.payloadpage_page), 99)
548575

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

0 commit comments

Comments
 (0)