Skip to content

Commit 0704166

Browse files
gh-65824: Improve the "less" prompt in pydoc (GH-116050)
Output the line number, the percentage and the help about how to get help or quit the pager. Inspired by the GNU man.
1 parent 7895a61 commit 0704166

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Lib/pydoc.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1685,8 +1685,17 @@ def plain(text):
16851685
def pipepager(text, cmd):
16861686
"""Page through text by feeding it to another program."""
16871687
import subprocess
1688+
env = os.environ.copy()
1689+
prompt_string = (
1690+
' '
1691+
'?ltline %lt?L/%L.'
1692+
':byte %bB?s/%s.'
1693+
'.'
1694+
'?e (END):?pB %pB\\%..'
1695+
' (press h for help or q to quit)')
1696+
env['LESS'] = '-RmPm{0}$PM{0}$'.format(prompt_string)
16881697
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
1689-
errors='backslashreplace')
1698+
errors='backslashreplace', env=env)
16901699
try:
16911700
with proc.stdin as pipe:
16921701
try:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve the ``less`` prompt in :mod:`pydoc`.

0 commit comments

Comments
 (0)