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.
This commit is contained in:
Serhiy Storchaka 2024-03-01 10:03:32 +02:00 committed by GitHub
parent 7895a61168
commit 0704166f9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -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:

View File

@ -0,0 +1 @@
Improve the ``less`` prompt in :mod:`pydoc`.