File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 2424import curses
2525import errno
2626import os
27+ import pydoc
2728import subprocess
2829import sys
2930
3031
3132def get_pager_command ():
32- command = os .environ .get ('PAGER' )
33+ command = os .environ .get ('PAGER' , 'less -r' ). split ( )
3334 return command
3435
3536
3637def page_internal (data ):
3738 """A more than dumb pager function."""
38- sys .stdout .write (data )
39+ if hasattr (pydoc , 'ttypager' ):
40+ pydoc .ttypager (data )
41+ else :
42+ sys .stdout .write (data )
3943
4044
4145def page (data , use_internal = False ):
@@ -44,11 +48,15 @@ def page(data, use_internal=False):
4448 page_internal (data )
4549 else :
4650 curses .endwin ()
47- popen = subprocess .Popen ([command ], stdin = subprocess .PIPE )
4851 try :
52+ popen = subprocess .Popen (command , stdin = subprocess .PIPE )
4953 popen .stdin .write (data )
5054 popen .stdin .close ()
5155 except OSError , e :
56+ if e .errno == errno .ENOENT :
57+ # pager command not found, fall back to internal pager
58+ page_internal (data )
59+ return
5260 if e .errno != errno .EPIPE :
5361 raise
5462 popen .wait ()
You can’t perform that action at this time.
0 commit comments