Changeset View
Changeset View
Standalone View
Standalone View
src/console/view/PhutilConsoleTable.php
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | /* -( Configuration )------------------------------------------------------ */ | ||||
public function setShowHeader($show_header) { | public function setShowHeader($show_header) { | ||||
$this->showHeader = $show_header; | $this->showHeader = $show_header; | ||||
return $this; | return $this; | ||||
} | } | ||||
/* -( Data )--------------------------------------------------------------- */ | /* -( Data )--------------------------------------------------------------- */ | ||||
public function addColumn($key, array $column) { | public function addColumn($key, array $column = array()) { | ||||
PhutilTypeSpec::checkMap($column, array( | PhutilTypeSpec::checkMap($column, array( | ||||
'title' => 'string', | 'title' => 'optional string', | ||||
'align' => 'optional string', | 'align' => 'optional string', | ||||
)); | )); | ||||
$this->columns[$key] = $column; | $this->columns[$key] = $column; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function addColumns(array $columns) { | public function addColumns(array $columns) { | ||||
foreach ($columns as $key => $column) { | foreach ($columns as $key => $column) { | ||||
Show All 9 Lines | foreach ($data as $key => $value) { | ||||
$this->widths[$key] = max( | $this->widths[$key] = max( | ||||
idx($this->widths, $key, 0), | idx($this->widths, $key, 0), | ||||
phutil_utf8_console_strlen($value)); | phutil_utf8_console_strlen($value)); | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
public function drawRows(array $rows) { | |||||
$this->data = array(); | |||||
$this->widths = array(); | |||||
foreach ($rows as $row) { | |||||
$this->addRow($row); | |||||
} | |||||
return $this->draw(); | |||||
} | |||||
/* -( Drawing )------------------------------------------------------------ */ | /* -( Drawing )------------------------------------------------------------ */ | ||||
protected function drawView() { | protected function drawView() { | ||||
return $this->drawLines( | return $this->drawLines( | ||||
array_merge( | array_merge( | ||||
$this->getHeader(), | $this->getHeader(), | ||||
$this->getBody(), | $this->getBody(), | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |