PrettyTables.jl
PrettyTables.jl copied to clipboard
Feature request: iterator
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
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.
This will take a huge rewrite
Arg
Do you still think it is doable in "finite time"?
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.
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
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.
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.
is it not possible to fix the widths based on the first row and cut the content the cells to fit the width?
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.
I see!
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 :)
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.
Perfect! When I have some time, I will propose an API and we can discuss!