-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add file-like pager: click.get_pager_file()
#1572
base: main
Are you sure you want to change the base?
Conversation
Fixes #50. Requires pallets/click#1572.
Thanks for looking at this, it's definitely an interesting approach. Have you confirmed that this works on Windows? Have you tested it with different pagers on Linux? |
Thanks for taking a look. I've tested both |
Extra testing is still TODO, but the new commits are a bit more reviewable, esp if you read them one at a time 👍 |
On MacOS and Linux (I did it with the |
Fixes #50. Requires pallets/click#1572.
Fixes #50. Requires pallets/click#1572.
Fixes #50. Requires pallets/click#1572.
Fixes #50. Requires pallets/click#1572.
8881005
to
61efc25
Compare
I love this one. It improves the code a lot. What is missing except for a round of conflict resolution? Does it really need extra test or is it covered by test of echo_via_pager? |
It needs testing in windows. The little testing I did suggested that it doesn't really work on windows yet. I got stuck trying to set up any kind of dev environment on windows to improve it. If anyone who has a windows setup already could help, that'd be much appreciated |
the mypy stuff is also blowing my mind a bit to be honest. I just spent about an hour trying to resolve all the type warnings and haven't yet managed to figure out what to do with things like variables that can hold either a text stream or a bytes stream |
@stefreak yep that'd be awesome. I'll have a go at updating this PR for you |
3c1b3ce
to
33ede8c
Compare
@stefreak I've updated this PR to latest main and it works okay for me on MacOS: |
@stefreak @craigds this might be able make it into 8.2.0. If you rebase this PR on #2775, I'm happy to accept a "stacked PR" like that. It should be possible to get #2775 in 8.2.0, see #2789 for more info. I'm working through all 8.1.8 and 8.2.0 potential PRs right now and updating that issue and a new one as well. |
This better exposes the file-like objects yielded by the three private pager functions, and also slightly reduces some code duplication
33ede8c
to
b544c40
Compare
In koordinates/kart we're in need of an output pager, and are already using click.
Trouble is, passing a generator to
echo_via_pager
requires that you're producing output in one place. That's not the case with a reasonably complex command - functions and modules delegating to each other all over the place.To use
echo_via_pager
, I essentially had to use some kind of concurrency - async or threads - and have my code feed output to a worker thread which would yield the output from a generator function, whichecho_via_pager
would consume.That worked, but then I realised click could just expose the file-like object it's using internally (which is usually a pipe to
less
).This PR does that.
click.get_pager_file
exposes a writable file like object which feeds into a pager. The semantics ofclick.echo_via_pager
haven't changed, but it now usesclick.get_pager_file
under the hood and merely feeds the generator contents into the file.