cli-table / cli-table3

Pretty unicode tables for the command line
MIT License
535 stars 44 forks source link

Feature: Add debugging capabilities #279

Closed speedytwenty closed 2 years ago

speedytwenty commented 2 years ago

With the introduction of #278, it will become possible to "easily" detect [layout] errors in the table data. Insofar I am not aware of any mechanism that could assist implementors in correcting their table layout. Yet I wonder if we could implement a simple debugging solution.

If we can now detect an invalid row count (rowSpan exceeds the total rows), perhaps we can detect an invalid column count—let the output be what it will be as is—but add a "debug" option which essentially creates an array of errors/warnings that implementors can use to debug. Eg.

const table = new Table({ debug: true });
console.log(table.toString());
console.log(table.debug); // Output row position and cell x/y positioning
console.log(table.errors); // Output any errors produced by the table (these are more like "warnings" than "errors")

To detect an invalid column count would require calculating the "max column" during the layout calculation and then re-traversing each row at the end to see that it satisfied the "max column". This traversal is presently unnecessary for rendering, but could be triggered with the debug flag in the table options.