kart icon indicating copy to clipboard operation
kart copied to clipboard

Add an output pager.

Open craigds opened this issue 5 years ago • 3 comments

Fixes #50

What a mission. This took way longer than I expected.

But I'm fairly happy with the results:

Screen Shot 2020-05-29 at 8 51 17 PM

Notes:

~I changed resolve_output_path to a contextmanager, and made it yield a file-like object that pushes lines of text into a queue, which are read by a worker thread which yields them via click.echo_via_pager.~

I implemented pallets/click#1572 to support doing this without having to use threads... that should ideally be merged and released before this PR is merged.

craigds avatar May 29 '20 08:05 craigds

In retrospect, this is quite roundabout. If I implement something in click itself I can just yield the filelike object it's already using for stdin to less. i.e. bypass the generator interface altogether. Then I dont need threads :)

I'll work on a click PR

craigds avatar May 30 '20 01:05 craigds

WIP here: https://github.com/craigds/click/tree/filelike-pager

craigds avatar May 30 '20 01:05 craigds

WIP here

Looks reasonable. I'm not sure if Click currently supports it, but does your approach break combining a pager with terminal output because the stream is closed when the context manager exits?

eg: prompt for X, view some text in the pager, quit the pager, prompt for Z, view some more output, ...

rcoup avatar Jun 01 '20 14:06 rcoup

maybe one day we'll return to this, but it's been almost three years, I'm sure we'll do it differently anyway

craigds avatar Mar 02 '23 01:03 craigds