Skip to content
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

Streaming of rows for table. #1

Open
piotrmurach opened this issue Feb 8, 2015 · 4 comments
Open

Streaming of rows for table. #1

piotrmurach opened this issue Feb 8, 2015 · 4 comments

Comments

@piotrmurach
Copy link
Owner

Creating tables where you know the desired column widths (number of characters or percentages) but you don't know the number of rows yet, because you'd like to stream the rows, not wait for all the data until rendering.

@spider-network
Copy link

+1

@piotrmurach
Copy link
Owner Author

Hi Michael,

I would really appreciate contribution from your side, even discussion of the api would be a huge step forward. Since you would like this feature implemented I assume you have an idea of how it should work.

I haven't spent much time thinking about the implementation but using my UML skills, this is what I believe the implemntation should behave like:
table_data_streaming

Currently TTY::Table is just a data structure with fairly elaborate way of rendering that data set back as formatted string. There is no notion of stream or partial rendering. Based on the above, we would need to have a way to inject a stream to table, keep it open when the data starts streaming, continue sending messages back to the stream and close it once done. The hard part is to write good api for that, for starters I would suggest the following:

table = TTY::Table.new(stream: 'some stream type such as stdout or file descriptor')
table.on_open do |stream, header|
   stream.puts header
end
table.on_receive_data do |stream, formatted_data_rows|
   stream.puts formatted_data_rows
end
table.on_close do |stream, footer|
   stream.puts footer
   stream.close
end
table.render_to_stream

# initial few data rows
table.chunk data
# some time later add few more rows
table.chunk data

Please let me have your thoughts!

@moortimis
Copy link

I've stumbled across this project in hope of achieving exactly what Peter has described above.

I'd be interested in any feedback or direction you could provide on how this can be achieved using TTY::Table.

Thanks in advance.

@piotrmurach
Copy link
Owner Author

@moortimis This hasn't been implemented yet in this library. I was hoping for discussion and review of my initial thoughts. Do you have an example of how you would like the streaming API to work? Would you mind commenting on my outline?

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

No branches or pull requests

3 participants