From 95a86417956a8e29e91ef9fd16e4cd1a1dcdfc3f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 28 Feb 2024 16:57:14 +0200 Subject: [PATCH 1/2] gh-65824: Improve the "less" prompt in pydoc Output the line number, the percent and help about how to get help or quit the pager. Inspired by the GNU man. --- Lib/pydoc.py | 11 ++++++++++- .../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 b0193b4a85164a..413001b67cd82f 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'] = '-ix8RmPm{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 00000000000000..7bc6ced120a7be --- /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`. From 608af04022a3ebdf93f60e79e5a5f3742d6c8401 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 28 Feb 2024 17:26:09 +0200 Subject: [PATCH 2/2] Update Lib/pydoc.py --- Lib/pydoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 413001b67cd82f..407c0205c7ab66 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1693,7 +1693,7 @@ def pipepager(text, cmd): '.' '?e (END):?pB %pB\\%..' ' (press h for help or q to quit)') - env['LESS'] = '-ix8RmPm{0}$PM{0}$'.format(prompt_string) + env['LESS'] = '-RmPm{0}$PM{0}$'.format(prompt_string) proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, errors='backslashreplace', env=env) try: