HomePhabricator

Add a `PhutilConsoleTable` class for drawing tables.

Description

Add a PhutilConsoleTable class for drawing tables.

Summary: Currently there is no easy way to draw a table. PhabricatorDaemonManagementStatusWorkflow draws a table in an ad-hoc way, but it would be useful to provide a more flexible mechanism to do so.

Test Plan:

$table = id(new PhutilConsoleTable())
  ->addColumn('foo', array('title' => 'Foo', 'align' => 'right'))
  ->addColumn('bar', array('title' => 'Foobar', 'align' => 'center'))
  ->addColumn('baz', array('title' => '日本語'))

  ->addRow(array('foo' => 12345, 'bar' => 'foo', 'baz' => 'baz'))
  ->addRow(array('foo' => '汉语漢語', 'bar' => '한국어조선말', 'baz' => 'ру́сский язы́к'))
  ->addRow(array('foo' => 'aaa', 'bar' => '✓✗', 'baz' => 'dddddddddddd'))
  ->addRow(array('foo' => '', 'bar' => '', 'baz' => ''));

$table->setBorders(false)->draw();
echo "\n";
$table->setBorders(true)->draw();

Output

table.png (257×497 px, 25 KB)

Reviewers: Blessed Reviewers, epriestley

Reviewed By: Blessed Reviewers, epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9533

Details

Provenance
joshuaspenceAuthored on
epriestleyCommitted on Jun 15 2014, 5:51 PM
epriestleyPushed on Jun 15 2014, 5:51 PM
Reviewer
Blessed Reviewers
Differential Revision
D9533: Add a `PhutilConsoleTable` class for drawing tables.
Parents
rPHUe57d872cbe61: Reduce the amount of information leaked into stack traces
Branches
Unknown
Tags
Unknown

Event Timeline