PrettyTables.jl icon indicating copy to clipboard operation
PrettyTables.jl copied to clipboard

Feature request: iterator

Open rveltz opened this issue 3 years ago • 13 comments

Hi,

Would it be possible to have an iterator so that we can print the table ourself? For example, this happens when monitoring a running process.

Thank you

rveltz avatar Apr 28 '21 23:04 rveltz

Yes, that's one very nice feature to have. We need some constraints like the columns must have a fixed size. This will take a huge rewrite in the printing engine but it is doable.

ronisbr avatar Apr 28 '21 23:04 ronisbr

This will take a huge rewrite

Arg

rveltz avatar Apr 29 '21 10:04 rveltz

Do you still think it is doable in "finite time"?

rveltz avatar Jun 27 '22 12:06 rveltz

Hi @rveltz !

Unfortunately I just cannot see this being implemented in the foreseeable future. I have a lot to do to make PrettyTables the default backend for DataFrames when using LaTeX and HTML. This kind of iterator will really require a huge rewrite in all backend and I just do not have time. Sorry about that!

I need first to stabilize and finish everything we have right now. After that, I can work on those improvements.

ronisbr avatar Jun 27 '22 12:06 ronisbr

Can you then point me to the part of the code where "a for loop" is used for printing the rows? I might be able to tweek it for my needs

Thqnks

rveltz avatar Jun 27 '22 13:06 rveltz

Hi @rveltz !

The lack of a unique for-loop is what makes it so challenging.

First, PrettyTables converts the input table to another one rendering each cell to string: https://github.com/ronisbr/PrettyTables.jl/blob/cb5ca2c5a1871f6a5e9f60934a20b0f4fa20db31/src/backends/text/fill.jl#L40

After, we can compute each column width, do some processing, and print everything here: https://github.com/ronisbr/PrettyTables.jl/blob/cb5ca2c5a1871f6a5e9f60934a20b0f4fa20db31/src/backends/text/print_table.jl#L11

We cannot have a single loop because we need to process all the cells that are going to be printed to obtain column widths. Hence, we need to have a mode in which the column widths are fixed but only one for-loop is used.

In fact, I am starting to think that is much easier if we create another backend using the functions in text-backend but with limitations to make the mode you are suggesting work.

ronisbr avatar Jun 28 '22 10:06 ronisbr

Just a side note: if we decide to make another backend with less functionality, then it should be very easy to accomplish when we decide an API.

ronisbr avatar Jun 28 '22 10:06 ronisbr

is it not possible to fix the widths based on the first row and cut the content the cells to fit the width?

rveltz avatar Jun 28 '22 10:06 rveltz

Yes, it is possible, but not in the current text backend, because it will have a totally different workflow. That's because it is easier to create a new backend.

ronisbr avatar Jun 28 '22 10:06 ronisbr

I see!

rveltz avatar Jun 28 '22 10:06 rveltz

But our discussion lead to a very nice ideia. I think we can make a new backend that will work waiting data and printing as it is available. We just need to discuss how the API will be :)

ronisbr avatar Jun 28 '22 10:06 ronisbr

the application I see is in very simple logging of iterative solver. I use a lot PP with BifurcationKit.jl once the computations are done and I would like to use it during the computations. The full fledge solution would probably be https://github.com/JuliaLogging/TerminalLoggers.jl/pull/8/files but the PR is stalled.

rveltz avatar Jun 28 '22 11:06 rveltz

Perfect! When I have some time, I will propose an API and we can discuss!

ronisbr avatar Jun 28 '22 13:06 ronisbr