summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-03-01 08:03:32 (GMT)
committerGitHub <noreply@github.com>2024-03-01 08:03:32 (GMT)
commit0704166f9a9c6028314d50b493670e7862c968b3 (patch)
tree5e3f638dd9607622d89999174c6a740d841d6de2 /Lib/pydoc.py
parent7895a61168aad4565a1d953104c9ec620e7c588f (diff)
downloadcpython-0704166f9a9c6028314d50b493670e7862c968b3.zip
cpython-0704166f9a9c6028314d50b493670e7862c968b3.tar.gz
cpython-0704166f9a9c6028314d50b493670e7862c968b3.tar.bz2
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.
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index b0193b4..407c020 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1685,8 +1685,17 @@ def plain(text):
def pipepager(text, cmd):
"""Page through text by feeding it to another program."""
import subprocess
+ env = os.environ.copy()
+ prompt_string = (
+ ' '
+ '?ltline %lt?L/%L.'
+ ':byte %bB?s/%s.'
+ '.'
+ '?e (END):?pB %pB\\%..'
+ ' (press h for help or q to quit)')
+ env['LESS'] = '-RmPm{0}$PM{0}$'.format(prompt_string)
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
- errors='backslashreplace')
+ errors='backslashreplace', env=env)
try:
with proc.stdin as pipe:
try: