function _drush_format_table

8.0.x output.inc _drush_format_table($rows, $header = FALSE, $widths = array(), $console_table_options = array())
6.x output.inc _drush_format_table($rows, $header = FALSE, $widths = array(), $console_table_options = array())
7.x output.inc _drush_format_table($rows, $header = FALSE, $widths = array(), $console_table_options = array())
master output.inc _drush_format_table($rows, $header = FALSE, $widths = array(), $console_table_options = array())

Related topics

3 calls to _drush_format_table()
drush_format_table in includes/output.inc
Format a table of data.
drush_print_table in includes/output.inc
Print a formatted table.
_drush_format_config_changes_table in commands/core/config.drush.inc
Print a table of config changes.

File

includes/output.inc, line 280

Code

function _drush_format_table($rows, $header = FALSE, $widths = array(), $console_table_options = array()) {
  // Add defaults.
  $tbl = new ReflectionClass('Console_Table');
  $console_table_options += array(CONSOLE_TABLE_ALIGN_LEFT, '');
  $tbl = $tbl->newInstanceArgs($console_table_options);

  $auto_widths = drush_table_column_autowidth($rows, $widths);

  // Do wordwrap on all cells.
  $newrows = array();
  foreach ($rows as $rowkey => $row) {
    foreach ($row as $col_num => $cell) {
      $newrows[$rowkey][$col_num] = wordwrap($cell, $auto_widths[$col_num], "\n", TRUE);
      if (isset($widths[$col_num])) {
        $newrows[$rowkey][$col_num] = str_pad($newrows[$rowkey][$col_num], $widths[$col_num]);
      }
    }
  }
  if ($header) {
    $headers = array_shift($newrows);
    $tbl->setHeaders($headers);
  }

  $tbl->addData($newrows);
  return $tbl;
}