kart
kart copied to clipboard
Add an output pager.
Fixes #50
What a mission. This took way longer than I expected.
But I'm fairly happy with the results:
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.
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
WIP here: https://github.com/craigds/click/tree/filelike-pager
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, ...
maybe one day we'll return to this, but it's been almost three years, I'm sure we'll do it differently anyway