https://github.com/python/cpython/commit/0704166f9a9c6028314d50b493670e7862c968b3
commit: 0704166f9a9c6028314d50b493670e7862c968b3
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-03-01T10:03:32+02:00
summary:

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.

files:
A Misc/NEWS.d/next/Library/2024-02-28-17-04-28.gh-issue-65824.gG8KR1.rst
M Lib/pydoc.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index b0193b4a85164a..407c0205c7ab66 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 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`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to