wp-cli / php-cli-tools

A collection of tools to help with PHP command line utilities
MIT License
676 stars 118 forks source link

Broken table layout when reporting WordPress vulnerabilities. #134

Open oscarssanchez opened 6 years ago

oscarssanchez commented 6 years ago

Hi,

Running wp vuln status through WordPress 4.9.6 breaks the table layout when the package reports any vulnerabilities with WordPress version (not plugins, not themes. See screenshots).

Expected behavior:

Table layout is not broken. Expected to see the same layout as it is with the reports of plugins and themes.

Current behavior:

The table layout breaks.

Steps to reproduce:

Run wp-vulnerability scanner through a WordPress 4.9.6 install 1.- wp vuln status

WP-CLI version: 2.0.0-alpha-2646dac

Screenshots:

Layout broken when reporting problems with WordPress 4.9.6: vuln1

Layout is fine when reporting no vulnerabilities with WordPress 4.9.7 vuln2

It seems like it has been a recurring issue (https://github.com/wp-cli/php-cli-tools/issues/106)

Thank you!

schlessera commented 6 years ago

@oscarssanchez This issue was fixed, however we couldn't fixed it in a general way without breaking backwards-compat.

That's why you need to use the second argument to display_items() to make this work.

If you pass all of your columns through WP_CLI::colorize(), then pass true as the second argument to display_items().

If you pass only select columns through WP_CLI::colorize(), then pass an array of booleans to display_items(), with each boolean denoting whether the respective column is using WP_CLI::colorize().

So, for example, if you have 4 columns and only the first one is passed through WP_CLI::colorize(), then use array( true, false, false, false ) as the second argument to display_items().

Please let me know if that helps resolve the issue.

UVLabs commented 3 years ago

@schlessera The new function to display a table seems to now be \WP_CLI\Utils\format_items so how do we address this with that function? The third param seems to just take in the column names

\WP_CLI\Utils\format_items( 'table', $items, array( 'module', 'key', 'status' ) );

alexisferat commented 2 years ago

@schlessera I encountered the same issue as @UVLabs and would like to know if there is a solution or a workaround.

slaFFik commented 1 year ago

@UVLabs @alexisferat Use a custom table registration instead of a generic \WP_CLI\Utils\format_items( 'table', $items ):

$table  = new \cli\Table();
$ascii  = new \cli\table\Ascii( [
    Colors::width( 'value 1', true ),
    Colors::width( 'value 2', false ),
    Colors::width( 'value 3', false )
] );

$ascii->setWidths( $widths );
$table->setRenderer( $ascii );

$table->setHeaders( [ 'module', 'key', 'status' ] );

$table->addRows( [ $rows ] );

$table->display();