##// END OF EJS Templates
Merge pull request #2738 from mdboom/pager-encoding...
Bradley M. Froehle -
r8990:66274d0e merge
parent child Browse files
Show More
@@ -29,6 +29,7 b' from __future__ import print_function'
29 29
30 30 import os
31 31 import re
32 import subprocess
32 33 import sys
33 34 import tempfile
34 35
@@ -41,6 +42,7 b' from IPython.utils.data import chop'
41 42 from IPython.utils import io
42 43 from IPython.utils.process import system
43 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 76 def _detect_screen_size(use_curses, screen_lines_def):
75 77 """Attempt to work out the number of lines on the screen.
76
78
77 79 This is called by page(). It can raise an error (e.g. when run in the
78 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 108 # http://bugs.python.org/issue10144
107 109 NCURSES_NO_SETBUF = os.environ.get('NCURSES_NO_SETBUF', None)
108 110 os.environ['NCURSES_NO_SETBUF'] = ''
109
111
110 112 # Proceed with curses initialization
111 113 scr = curses.initscr()
112 114 screen_lines_real,screen_cols = scr.getmaxyx()
@@ -117,7 +119,7 b' def _detect_screen_size(use_curses, screen_lines_def):'
117 119 del os.environ['NCURSES_NO_SETBUF']
118 120 else:
119 121 os.environ['NCURSES_NO_SETBUF'] = NCURSES_NO_SETBUF
120
122
121 123 # Restore terminal state in case endwin() didn't.
122 124 termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags)
123 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 220 retval = None
219 221 # if I use popen4, things hang. No idea why.
220 222 #pager,shell_out = os.popen4(pager_cmd)
221 pager = os.popen(pager_cmd,'w')
222 pager.write(strng)
223 pager.close()
224 retval = pager.close() # success returns None
223 pager = os.popen(pager_cmd, 'w')
224 try:
225 pager_encoding = pager.encoding or sys.stdout.encoding
226 pager.write(py3compat.cast_bytes_py2(
227 strng, encoding=pager_encoding))
228 finally:
229 retval = pager.close()
225 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 232 retval = None
228 233 else:
229 234 retval = 1
@@ -338,4 +343,3 b" def snip_print(str,width = 75,print_full = 0,header = ''):"
338 343 if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y':
339 344 page(str)
340 345 return snip
341
General Comments 0
You need to be logged in to leave comments. Login now