function drush_print_table

8.0.x output.inc drush_print_table($rows, $header = FALSE, $widths = array(), $handle = NULL)
6.x output.inc drush_print_table($rows, $header = FALSE, $widths = array(), $handle = NULL)
7.x output.inc drush_print_table($rows, $header = FALSE, $widths = array(), $handle = NULL)
3.x drush.inc drush_print_table($rows, $header = FALSE, $widths = array())
4.x drush.inc drush_print_table($rows, $header = FALSE, $widths = array(), $handle = NULL)
5.x output.inc drush_print_table($rows, $header = FALSE, $widths = array(), $handle = NULL)
master output.inc drush_print_table($rows, $header = FALSE, $widths = array(), $handle = NULL)

Print a formatted table.

Parameters

$rows: The rows to print.

$header: If TRUE, the first line will be treated as table header.

$widths: The widths of each column (in characters) to use - if not specified this will be determined automatically, based on a "best fit" algorithm.

$handle: File handle to write to. NULL will write to standard output, STDERR will write to the standard error. See http://php.net/manual/en/features.commandline.io-streams.php

Return value

$tbl Use $tbl->getTable() to get the output from the return value.

Related topics

22 calls to drush_print_table()
drush_choice in includes/drush.inc
Ask the user to select an item from a list. From a provided associative array, drush_choice will display all of the questions, numbered from 1 to N, and return the item the user selected. "0" is always cancel; entering a blank line is also…
drush_core_global_options in commands/core/core.drush.inc
drush_core_requirements in commands/core/core.drush.inc
Command callback. Provides information from the 'Status Reports' admin page.
drush_core_shell_alias in commands/core/shellalias.drush.inc
Print out the specified shell aliases.
drush_core_status in commands/core/core.drush.inc
Command callback. Provides a birds-eye view of the current Drupal installation.

... See full list

File

includes/output.inc, line 207

Code

function drush_print_table($rows, $header = FALSE, $widths = array(), $handle = NULL) {
  $tbl = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, '');

  $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);
  $output = $tbl->getTable();
  if (!stristr(PHP_OS, 'WIN')) {
    $output = str_replace("\r\n", PHP_EOL, $output);
  }

  drush_print($output, 0, $handle);
  return $tbl;
}