columnar icon indicating copy to clipboard operation
columnar copied to clipboard

Possibly to use as a generator?

Open retr0h opened this issue 4 years ago • 2 comments

I have a fairly large data set which ultimately is printed with click.echo_via_pager. Would it be possible to supply a generator to columnar.columnar?

Thanks

retr0h avatar Jul 11 '20 02:07 retr0h

Hey @retr0h , sorry for the wait, I'm just getting back to this. I admit that I have never used click.echo_via_pager, but taking it quick look at the docs it looks like you could write a generator that feeds chunks of text into columnar and then yields the output to click. Something like this:

import click
from columnar import columnar

def my_generator():
    while True: 
        next_chunk = get_text_chunk_from_my_source()
        if next_chunk == "":
            break
        next_table = columnar(next_chunk)
        yield next_table

def main():
    click.echo_via_pager(my_generator)

acksmaggart avatar Dec 27 '21 22:12 acksmaggart

Thank you @MaxTaggart

retr0h avatar Jan 10 '22 21:01 retr0h