Skip to content

gh-65824: Improve help() when MANPAGER and PAGER variables are not set #21520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,8 @@ def getpager():
if sys.platform == 'win32':
return lambda text: tempfilepager(plain(text), 'more <')
if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
return lambda text: pipepager(text, 'less')
cmd = 'less "-P?e(END) .(q to quit)" --quit-at-eof'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do also considering adding the -X and -F (latter is the same as --quit-if-one-screen) flags.

From the less documentation,

-X causes less to not clear screen upon quit

-X or --no-init

Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.

and with -F, it quits if the help fits in one screen

-F or --quit-if-one-screen

Causes less to automatically exit if the entire file can be displayed on the first screen.
Suggested change
cmd = 'less "-P?e(END) .(q to quit)" --quit-at-eof'
cmd = 'less "-P?e(END) .(q to quit)" -X --quit-if-one-screen --quit-at-eof'

return lambda text: pipepager(text, cmd)

import tempfile
(fd, filename) = tempfile.mkstemp()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When the ``MANPAGER`` and ``PAGER`` environment variables are not set,
interactive :func:`help` now quits if enter is pressed on the last line.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add info about "(q to quit)" message on the status line?