Skip to content

Commit

Permalink
Issue #2057651 by greg.1.anderson: Fixed Drush help uses less than ha…
Browse files Browse the repository at this point in the history
…lf the available terminal window width when formatting output. We were not yet accounting for the fact that columns can have named ids and not just integers.
  • Loading branch information
weitzman committed Aug 5, 2013
1 parent baad2d0 commit 98e4e40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions commands/core/help.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function drush_print_help($command) {
if (!empty($command[$key])) {
drush_print(dt($value) . ':');
$rows = drush_format_help_section($command, $key);
drush_print_table($rows, FALSE, array(40));
drush_print_table($rows, FALSE, array('label' => 40));
unset($rows);
drush_print();
}
Expand Down Expand Up @@ -362,7 +362,7 @@ function drush_help_listing_print($command_categories, $format) {
$rows = array();
foreach($commands as $cmd => $command) {
$name = $command['aliases'] ? $cmd . ' (' . implode(', ', $command['aliases']) . ')': $cmd;
$rows[$cmd] = array($name, $command['description']);
$rows[$cmd] = array('name' => $name, 'description' => $command['description']);
}

// Vary the output by mode: CLI or HTML
Expand All @@ -372,7 +372,7 @@ function drush_help_listing_print($command_categories, $format) {
}
else {
drush_print($info['title'] . ": (" . $key . ")");
drush_print_table($rows, FALSE, array(0 => 20));
drush_print_table($rows, FALSE, array('name' => 20));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function _drush_bootstrap_drush() {
// information to the drush output via post-processing, the
// --reserve-margin flag can be used to declare how much
// space to leave out. This only affects drush functions
// such as drush_print_table that wrap the output.
// such as drush_print_table() that wrap the output.
$columns -= drush_get_option('reserve-margin', 0);
drush_set_context('DRUSH_COLUMNS', $columns);

Expand Down
32 changes: 16 additions & 16 deletions includes/output.inc
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ function drush_html_to_text($html, $allowed_tags = NULL) {
* @param $header
* If TRUE, the first line will be treated as table header.
* @param $widths
* The widths of each column (in characters) to use - if not specified this
* will be determined automatically, based on a "best fit" algorithm.
* An associative array whose keys are column IDs and values are widths of each column (in characters).
* If not specified this will be determined automatically, based on a "best fit" algorithm.
* @param $handle
* File handle to write to. NULL will write
* to standard output, STDERR will write to the standard
Expand All @@ -232,8 +232,8 @@ function drush_print_table($rows, $header = FALSE, $widths = array(), $handle =
* @param $header
* If TRUE, the first line will be treated as table header.
* @param $widths
* The widths of each column (in characters) to use - if not specified this
* will be determined automatically, based on a "best fit" algorithm.
* An associative array whose keys are column IDs and values are widths of each column (in characters).
* If not specified this will be determined automatically, based on a "best fit" algorithm.
* @param array $console_table_options
* An array that is passed along when constructing a Console_Table instance.
* @return $output
Expand Down Expand Up @@ -582,33 +582,33 @@ function drush_table_column_autowidth($rows, $widths) {
$auto_widths = $widths;

// First we determine the distribution of row lengths in each column.
// This is an array of descending character length keys (i.e. starting at
// This is an array of descending character length keys (i.e. starting at
// the rightmost character column), with the value indicating the number
// of rows where that character column is present.
$col_dist = array();
foreach ($rows as $rowkey => $row) {
foreach ($row as $col_num => $cell) {
if (empty($widths[$col_num])) {
foreach ($row as $col_id => $cell) {
if (empty($widths[$col_id])) {
$length = strlen($cell);
if ($length == 0) {
$col_dist[$col_num][0] = 0;
$col_dist[$col_id][0] = 0;
}
while ($length > 0) {
if (!isset($col_dist[$col_num][$length])) {
$col_dist[$col_num][$length] = 0;
if (!isset($col_dist[$col_id][$length])) {
$col_dist[$col_id][$length] = 0;
}
$col_dist[$col_num][$length]++;
$col_dist[$col_id][$length]++;
$length--;
}
}
}
}
foreach ($col_dist as $col_num => $count) {
foreach ($col_dist as $col_id => $count) {
// Sort the distribution in decending key order.
krsort($col_dist[$col_num]);
krsort($col_dist[$col_id]);
// Initially we set all columns to their "ideal" longest width
// - i.e. the width of their longest column.
$auto_widths[$col_num] = max(array_keys($col_dist[$col_num]));
$auto_widths[$col_id] = max(array_keys($col_dist[$col_id]));
}

// We determine what width we have available to use, and what width the
Expand All @@ -622,7 +622,7 @@ function drush_table_column_autowidth($rows, $widths) {
while ($auto_width_current > $available_width) {
$count = 0;
$width = 0;
foreach ($col_dist as $col_num => $counts) {
foreach ($col_dist as $col_id => $counts) {
// If we are just starting out, select the first column.
if ($count == 0 ||
// OR: if this column would cause less wrapping than the currently
Expand All @@ -634,7 +634,7 @@ function drush_table_column_autowidth($rows, $widths) {
(current($counts) == $count && key($counts) > $width)) {
// Select the column number, and record the count and current width
// for later comparisons.
$column = $col_num;
$column = $col_id;
$count = current($counts);
$width = key($counts);
}
Expand Down

0 comments on commit 98e4e40

Please sign in to comment.