Skip to content

Commit 069e740

Browse files
committed
fall back to less and pydoc.ttypager if pager is not found
1 parent 5929cc3 commit 069e740

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

bpython/pager.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@
2424
import curses
2525
import errno
2626
import os
27+
import pydoc
2728
import subprocess
2829
import sys
2930

3031

3132
def get_pager_command():
32-
command = os.environ.get('PAGER')
33+
command = os.environ.get('PAGER', 'less -r').split()
3334
return command
3435

3536

3637
def 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

4145
def 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()

0 commit comments

Comments
 (0)