When attempting to help users disambiguate between things presented in a table, we may want to provide valance to the user by setting the background colors:
$table = id(new PhutilConsoleTable()) ->setShowHeader(false) ->setBorders(true) ->setPadding(1) ->addColumn('command', array('title' => 'Command')) ->addColumn('usage', array('title' => 'Usage')); $table->addRow(array( 'command' => phutil_console_format( "<bg:red>** %s **</bg>", 'arc thingy' ), 'usage' => 'Does the dangerous thingy.', )); $table->addRow(array( 'command' => phutil_console_format( "<bg:green>** %s **</bg>", 'arc dongle' ), 'usage' => 'Does the safe dongle.', )); $table->draw();
Unfortunately, PhutilConsoleTable, being a PhutilConsoleView, forcibly escapes all ANSI escape codes before displaying them:
+==============+============================+ | <ESC>[41m<ESC>[1m arc thingy <ESC>[m<ESC>[49m | Does the dangerous thingy. | | <ESC>[42m<ESC>[1m arc dongle <ESC>[m<ESC>[49m | Does the safe dongle. | +==============+============================+
Interestingly, the widths are calculated correctly.
As with any escaping or similar transformation, turning it off at one layer requires that the layer built atop it take full responsibility for escaping, itself -- or T8243 will be made worse. While the below potential solution is sufficient to implement the feature request, it does so at the cost of introducing a loaded gun, and possibly breaking the encapsulation (and purpose) of PhutilConsoleView.