Show More
@@ -1,51 +1,41 | |||||
1 | # encoding: utf-8 |
|
|||
2 |
|
|
1 | """A payload based version of page.""" | |
3 |
|
2 | |||
4 | # Copyright (c) IPython Development Team. |
|
3 | # Copyright (c) IPython Development Team. | |
5 | # Distributed under the terms of the Modified BSD License. |
|
4 | # Distributed under the terms of the Modified BSD License. | |
6 |
|
5 | |||
7 | import warnings |
|
6 | import warnings | |
8 | from IPython.core.getipython import get_ipython |
|
7 | from IPython.core.getipython import get_ipython | |
9 |
|
8 | |||
|
9 | # see https://github.com/ipython/ipykernel/issues/1304 | |||
|
10 | # this should be moved to ipykernel and removed in the long run. | |||
|
11 | ||||
10 |
|
12 | |||
11 | def page(strng, start=0, screen_lines=0, pager_cmd=None): |
|
13 | def page(strng, start=0, screen_lines=0, pager_cmd=None): | |
12 | """Print a string, piping through a pager. |
|
14 | """Print a string, piping through a pager. | |
13 |
|
15 | |||
14 | This version ignores the screen_lines and pager_cmd arguments and uses |
|
16 | This version ignores the screen_lines and pager_cmd arguments and uses | |
15 | IPython's payload system instead. |
|
17 | IPython's payload system instead. | |
16 |
|
18 | |||
17 | Parameters |
|
19 | Parameters | |
18 | ---------- |
|
20 | ---------- | |
19 | strng : str or mime-dict |
|
21 | strng : str or mime-dict | |
20 | Text to page, or a mime-type keyed dict of already formatted data. |
|
22 | Text to page, or a mime-type keyed dict of already formatted data. | |
21 | start : int |
|
23 | start : int | |
22 | Starting line at which to place the display. |
|
24 | Starting line at which to place the display. | |
23 | """ |
|
25 | """ | |
24 |
|
26 | |||
25 | # Some routines may auto-compute start offsets incorrectly and pass a |
|
27 | # Some routines may auto-compute start offsets incorrectly and pass a | |
26 | # negative value. Offset to 0 for robustness. |
|
28 | # negative value. Offset to 0 for robustness. | |
27 | start = max(0, start) |
|
29 | start = max(0, start) | |
28 | shell = get_ipython() |
|
30 | shell = get_ipython() | |
29 |
|
31 | |||
30 | if isinstance(strng, dict): |
|
32 | if isinstance(strng, dict): | |
31 | data = strng |
|
33 | data = strng | |
32 | else: |
|
34 | else: | |
33 | data = {'text/plain' : strng} |
|
35 | data = {'text/plain' : strng} | |
34 | payload = dict( |
|
36 | payload = dict( | |
35 | source='page', |
|
37 | source='page', | |
36 | data=data, |
|
38 | data=data, | |
37 | start=start, |
|
39 | start=start, | |
38 | ) |
|
40 | ) | |
39 | shell.payload_manager.write_payload(payload) |
|
41 | shell.payload_manager.write_payload(payload) | |
40 |
|
||||
41 |
|
||||
42 | def install_payload_page(): |
|
|||
43 | """DEPRECATED, use show_in_pager hook |
|
|||
44 |
|
||||
45 | Install this version of page as IPython.core.page.page. |
|
|||
46 | """ |
|
|||
47 | warnings.warn("""install_payload_page is deprecated. |
|
|||
48 | Use `ip.set_hook('show_in_pager, page.as_hook(payloadpage.page))` |
|
|||
49 | """) |
|
|||
50 | from IPython.core import page as corepage |
|
|||
51 | corepage.page = page |
|
General Comments 0
You need to be logged in to leave comments.
Login now