Show More
@@ -29,6 +29,7 b' from __future__ import print_function' | |||||
29 |
|
29 | |||
30 | import os |
|
30 | import os | |
31 | import re |
|
31 | import re | |
|
32 | import subprocess | |||
32 | import sys |
|
33 | import sys | |
33 | import tempfile |
|
34 | import tempfile | |
34 |
|
35 | |||
@@ -41,6 +42,7 b' from IPython.utils.data import chop' | |||||
41 | from IPython.utils import io |
|
42 | from IPython.utils import io | |
42 | from IPython.utils.process import system |
|
43 | from IPython.utils.process import system | |
43 | from IPython.utils.terminal import get_terminal_size |
|
44 | from IPython.utils.terminal import get_terminal_size | |
|
45 | from IPython.utils import py3compat | |||
44 |
|
46 | |||
45 |
|
47 | |||
46 | #----------------------------------------------------------------------------- |
|
48 | #----------------------------------------------------------------------------- | |
@@ -73,7 +75,7 b' def page_dumb(strng, start=0, screen_lines=25):' | |||||
73 |
|
75 | |||
74 | def _detect_screen_size(use_curses, screen_lines_def): |
|
76 | def _detect_screen_size(use_curses, screen_lines_def): | |
75 | """Attempt to work out the number of lines on the screen. |
|
77 | """Attempt to work out the number of lines on the screen. | |
76 |
|
78 | |||
77 | This is called by page(). It can raise an error (e.g. when run in the |
|
79 | This is called by page(). It can raise an error (e.g. when run in the | |
78 | test suite), so it's separated out so it can easily be called in a try block. |
|
80 | test suite), so it's separated out so it can easily be called in a try block. | |
79 | """ |
|
81 | """ | |
@@ -106,7 +108,7 b' def _detect_screen_size(use_curses, screen_lines_def):' | |||||
106 | # http://bugs.python.org/issue10144 |
|
108 | # http://bugs.python.org/issue10144 | |
107 | NCURSES_NO_SETBUF = os.environ.get('NCURSES_NO_SETBUF', None) |
|
109 | NCURSES_NO_SETBUF = os.environ.get('NCURSES_NO_SETBUF', None) | |
108 | os.environ['NCURSES_NO_SETBUF'] = '' |
|
110 | os.environ['NCURSES_NO_SETBUF'] = '' | |
109 |
|
111 | |||
110 | # Proceed with curses initialization |
|
112 | # Proceed with curses initialization | |
111 | scr = curses.initscr() |
|
113 | scr = curses.initscr() | |
112 | screen_lines_real,screen_cols = scr.getmaxyx() |
|
114 | screen_lines_real,screen_cols = scr.getmaxyx() | |
@@ -117,7 +119,7 b' def _detect_screen_size(use_curses, screen_lines_def):' | |||||
117 | del os.environ['NCURSES_NO_SETBUF'] |
|
119 | del os.environ['NCURSES_NO_SETBUF'] | |
118 | else: |
|
120 | else: | |
119 | os.environ['NCURSES_NO_SETBUF'] = NCURSES_NO_SETBUF |
|
121 | os.environ['NCURSES_NO_SETBUF'] = NCURSES_NO_SETBUF | |
120 |
|
122 | |||
121 | # Restore terminal state in case endwin() didn't. |
|
123 | # Restore terminal state in case endwin() didn't. | |
122 | termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags) |
|
124 | termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags) | |
123 | # Now we have what we needed: the screen size in rows/columns |
|
125 | # Now we have what we needed: the screen size in rows/columns | |
@@ -218,12 +220,15 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):' | |||||
218 | retval = None |
|
220 | retval = None | |
219 | # if I use popen4, things hang. No idea why. |
|
221 | # if I use popen4, things hang. No idea why. | |
220 | #pager,shell_out = os.popen4(pager_cmd) |
|
222 | #pager,shell_out = os.popen4(pager_cmd) | |
221 | pager = os.popen(pager_cmd,'w') |
|
223 | pager = os.popen(pager_cmd, 'w') | |
222 |
|
|
224 | try: | |
223 | pager.close() |
|
225 | pager_encoding = pager.encoding or sys.stdout.encoding | |
224 | retval = pager.close() # success returns None |
|
226 | pager.write(py3compat.cast_bytes_py2( | |
|
227 | strng, encoding=pager_encoding)) | |||
|
228 | finally: | |||
|
229 | retval = pager.close() | |||
225 | except IOError as msg: # broken pipe when user quits |
|
230 | except IOError as msg: # broken pipe when user quits | |
226 | if msg.args == (32,'Broken pipe'): |
|
231 | if msg.args == (32, 'Broken pipe'): | |
227 | retval = None |
|
232 | retval = None | |
228 | else: |
|
233 | else: | |
229 | retval = 1 |
|
234 | retval = 1 | |
@@ -338,4 +343,3 b" def snip_print(str,width = 75,print_full = 0,header = ''):" | |||||
338 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': |
|
343 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': | |
339 | page(str) |
|
344 | page(str) | |
340 | return snip |
|
345 | return snip | |
341 |
|
General Comments 0
You need to be logged in to leave comments.
Login now