From 0704166f9a9c6028314d50b493670e7862c968b3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 1 Mar 2024 10:03:32 +0200 Subject: 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. --- Lib/pydoc.py | 11 ++++++++++- .../Library/2024-02-28-17-04-28.gh-issue-65824.gG8KR1.rst | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-02-28-17-04-28.gh-issue-65824.gG8KR1.rst 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: 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 0000000..7bc6ced --- /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`. -- cgit v0.12