douglasg14b / BetterConsoleTables

Faster, colorable, more configurable, and more robust console colors & tables for C# console applications
GNU Lesser General Public License v3.0
92 stars 16 forks source link

Live table updates #18

Closed amcelmon-clgx closed 4 years ago

amcelmon-clgx commented 4 years ago

I frequently find myself needing to display real time tables in console apps. Is it possible to update the table in a loop and write row by row instead of building the entire table and printing it all at once?

douglasg14b commented 4 years ago

It is not. The entire table is generated in one go.

Is there a performance problem with re-printing the entire table? It should generate pretty quickly, as performance was one of my concerns for this lib.

V2 (in beta) allows for the updating of table data without re-creating the table, but you still need to ToString() and re-print it.

amcelmon-clgx commented 4 years ago

Thanks for the response! Performance is great. My use cases are typically log running "log" type scripts where I output data the entire time for analysis. In V2, could I just append the latest row to output and print one row at a time.

Right now its looks like this


Console.WriteLine("Header\tHeader2\tHeader3");

//runs for hours
foreach (Object in List)
{
Console.WriteLine("Value 1 \tValue 2\tHeader3");
}

I like to see the data as it comes, rather than waiting for the full pull to output it. :)

douglasg14b commented 4 years ago

You can get the same visualization of data being added row-by-row by re-printing the entire table each time data comes in. Visually it will look the same as if you where "adding" rows to the bottom as each row of data was received. You just need to reset the position of the cursor to Console.SetCursorPosition(0,0) upon each Console.Write(tableString) so that it overwrites the console buffer appropriately. I believe you can add rows to an existing table, and just ToString() it every time you add a new row.

This is how I achieve real-time dashboards that rapidly update various values on the fly.


The problem with adding rows a standalone manner is that the column widths may no longer match previous rows if the content changes, so the entire table must be generated as a single item to guarantee that text will fit and that the columns align.

However the performance will begin to suffer if you are rendering tens of thousands of rows that need to be re-generated... You could just create a table with say the last 10 rows of data, and print that, which will also simulate the view of a scrolling table of data. Though you will be unable to scroll back up.

TL;DR: You can achieve this, it just takes some effort on your part to manipulate the table's input to simulate what you want.


V2 does allow you to print a table without headers, you could play around with that and see , note that the table API has changed. I do not have it documented yet, refer to the testing project for usage examples somewhere in the mess.

One goal for V2 was to enable a viewable "window" in the table. So that you could scroll through the table, without having to print the entire thing. THis involves printing and re-writing the console area as the scrolling occurs. I have no idea when or if I'll get around to making such a thing possible.... But it would fit your use case exactly.

amcelmon-clgx commented 4 years ago

Thanks again for the detailed reply. I'll look into piecing it together as I move though and see how it goes.

douglasg14b commented 4 years ago

Closing this as there has been no movement.