From: Serhiy Storchaka Date: Fri, 1 Mar 2024 08:03:32 +0000 (+0200) Subject: gh-65824: Improve the "less" prompt in pydoc (GH-116050) X-Git-Tag: v3.13.0a5~162 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0704166f9a9c6028314d50b493670e7862c968b3;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Lib/pydoc.py b/Lib/pydoc.py index b0193b4a8516..407c0205c7ab 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: diff --git a/Misc/NEWS.d/next/Library/2024-02-28-17-04-28.gh-issue-65824.gG8KR1.rst b/Misc/NEWS.d/next/Library/2024-02-28-17-04-28.gh-issue-65824.gG8KR1.rst new file mode 100644 index 000000000000..7bc6ced120a7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-02-28-17-04-28.gh-issue-65824.gG8KR1.rst @@ -0,0 +1 @@ +Improve the ``less`` prompt in :mod:`pydoc`.