Skip to content

_pyrepl/pager.py: call less with --clear-screen#146382

Merged
pablogsal merged 1 commit intopython:mainfrom
StanFromIreland:pager-less
Mar 28, 2026
Merged

_pyrepl/pager.py: call less with --clear-screen#146382
pablogsal merged 1 commit intopython:mainfrom
StanFromIreland:pager-less

Conversation

@StanFromIreland
Copy link
Copy Markdown
Member

Since this is only a cosmetic change, I don't think it qualifies for a news entry.

Currently, text is written bottom-to-top, resulting in odd placement for copyright():

Screenshot From 2026-03-24 15-30-53

This patch fixes that:

image

By passing --clear-screen (-c) to less, which "causes full screen repaints to be painted from the top line down."

@pablogsal pablogsal merged commit 087a5f6 into python:main Mar 28, 2026
61 checks passed
@pablogsal
Copy link
Copy Markdown
Member

pablogsal commented Mar 28, 2026

Thank you for your contribution! :)

@StanFromIreland StanFromIreland deleted the pager-less branch March 28, 2026 17:27
@StanFromIreland
Copy link
Copy Markdown
Member Author

Thanks for your merge!

@skirpichev
Copy link
Copy Markdown
Member

Sorry, @StanFromIreland, it doesn't look as a cosmetic change. IMO, it's a regression, which introduces rather unhelpful behavior of the REPL.

Here old behavior:
Screenshot From 2026-04-04 04-11-10

So, for small docstring - you can see all nearby repl interaction without scrolling.

Now it's not the case:
Screenshot From 2026-04-04 03-29-30

BTW, in the real world - my console size would be much bigger. So, more wasted space...

Maybe we could solve your issue (if it exists at all) in a different way? BTW, why to keep pager at all for small texts? I think that git tools do this per default only if text doesn't fit to the screen (-F option).

The patch:

diff --git a/Lib/_pyrepl/pager.py b/Lib/_pyrepl/pager.py
index 92afaa5933a..f937d7973d8 100644
--- a/Lib/_pyrepl/pager.py
+++ b/Lib/_pyrepl/pager.py
@@ -138,7 +138,7 @@ def pipe_pager(text: str, cmd: str, title: str = '') -> None:
         '.'
         '?e (END):?pB %pB\\%..'
         ' (press h for help or q to quit)')
-    env['LESS'] = '-RcmPm{0}$PM{0}$'.format(prompt_string)
+    env['LESS'] = '-F -RmPm{0}$PM{0}$'.format(prompt_string)
     proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
                             errors='backslashreplace', env=env)
     assert proc.stdin is not None

The behavior for git tools could be customized, i.e. they respect the LESS variable. Maybe we also should introduce some opportunity to opt-out from defaults?

@StanFromIreland
Copy link
Copy Markdown
Member Author

StanFromIreland commented Apr 4, 2026

I'm afraid I can't reproduce your shown old behaviour, I always get the pager anyway, testing on 3.14 (which didn't get this fix):

image

Maybe this is down to different lesses? I'm not sure what the output on Mac would be.

@skirpichev
Copy link
Copy Markdown
Member

I'm afraid I can't reproduce your shown old behaviour, I always get the pager anyway

You are right, this happens only if you near of the bottom of the screen. Though, it's a sort of common case in a long REPL session.

BTW, with added -F option - this happens always. Are there reasons to keep pager for a small texts? Terminals e.g. usually have own capabilities for text search and so on.

I'm not sure what the output on Mac would be.

No, it was linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants