Debian Codegraph @

IPython/core/payloadpage.py

raw
1 """A payload based version of page."""
2
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
5
6 import warnings
7 from IPython.core.getipython import get_ipython
8
9 # see https://github.com/ipython/ipykernel/issues/1304
10 # this should be moved to ipykernel and removed in the long run.
11
12
13 def page(strng, start=0, screen_lines=0, pager_cmd=None):
14 """Print a string, piping through a pager.
15
16 This version ignores the screen_lines and pager_cmd arguments and uses
17 IPython's payload system instead.
18
19 Parameters
20 ----------
21 strng : str or mime-dict
22 Text to page, or a mime-type keyed dict of already formatted data.
23 start : int
24 Starting line at which to place the display.
25 """
26
27 # Some routines may auto-compute start offsets incorrectly and pass a
28 # negative value. Offset to 0 for robustness.
29 start = max(0, start)
30 shell = get_ipython()
31
32 if isinstance(strng, dict):
33 data = strng
34 else:
35 data = {"text/plain": strng}
36 payload = dict(
37 source="page",
38 data=data,
39 start=start,
40 )
41 shell.payload_manager.write_payload(payload)