]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-65824: Improve the "less" prompt in pydoc (GH-116050)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 1 Mar 2024 08:03:32 +0000 (10:03 +0200)
committerGitHub <noreply@github.com>
Fri, 1 Mar 2024 08:03:32 +0000 (10:03 +0200)
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
Misc/NEWS.d/next/Library/2024-02-28-17-04-28.gh-issue-65824.gG8KR1.rst [new file with mode: 0644]

index b0193b4a85164a73471c610e8f36137328e04c34..407c0205c7ab66560d4cbfe14c1839160e18b5a5 100755 (executable)
@@ -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 (file)
index 0000000..7bc6ced
--- /dev/null
@@ -0,0 +1 @@
+Improve the ``less`` prompt in :mod:`pydoc`.