? .drush.php.swp
? .svn
? drushrc.php
? update_status
? z
? includes/.drush.inc.swp
? includes/table.inc
Index: drush.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush.php,v
retrieving revision 1.64
diff -u -r1.64 drush.php
--- drush.php	6 May 2009 19:35:59 -0000	1.64
+++ drush.php	11 May 2009 17:09:31 -0000
@@ -23,6 +23,7 @@
 require_once DRUSH_BASE_PATH . '/includes/drush.inc';
 require_once DRUSH_BASE_PATH . '/includes/backend.inc';
 require_once DRUSH_BASE_PATH . '/includes/context.inc';
+require_once DRUSH_BASE_PATH . '/includes/table.inc';
 
 drush_set_context('argc', $GLOBALS['argc']);
 drush_set_context('argv', $GLOBALS['argv']);
Index: commands/core/core.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/core.drush.inc,v
retrieving revision 1.27
diff -u -r1.27 core.drush.inc
--- commands/core/core.drush.inc	8 May 2009 03:46:15 -0000	1.27
+++ commands/core/core.drush.inc	11 May 2009 17:09:38 -0000
@@ -158,7 +158,7 @@
             $pipe[] = "\"$key\"";
           }
         }
-        drush_print_table($rows, 2);
+        drush_print_table($rows, 2, FALSE, array(0 => 20));
         $printed_rows = array_merge($printed_rows, $rows);
       }
       else {
Index: includes/command.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/command.inc,v
retrieving revision 1.31
diff -u -r1.31 command.inc
--- includes/command.inc	11 May 2009 14:43:34 -0000	1.31
+++ includes/command.inc	11 May 2009 17:09:56 -0000
@@ -413,7 +413,15 @@
         $files = drush_scan_directory($path, '\.drush\.inc$');
         foreach ($files as $filename => $info) {
           require_once($filename);
-          $list[basename($filename, '.drush.inc')] = $filename;
+          $base = basename($filename, '.drush.inc');
+          $info = array('status' => 1);
+          $func = $base . '_drush_info';
+          if (function_exists($func)) {
+            $info = $func();
+          }
+          if ($info['status']) {
+            $list[$base] = $filename;
+          }
         }
       }
     }
Index: includes/drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/drush.inc,v
retrieving revision 1.37
diff -u -r1.37 drush.inc
--- includes/drush.inc	11 May 2009 15:20:16 -0000	1.37
+++ includes/drush.inc	11 May 2009 17:10:12 -0000
@@ -345,7 +345,7 @@
                 // '[command] is a token representing the current command. @see pm_drush_engine_version_control().
                 $rows[] = array(str_replace('[command]', $commandstring, $name), dt($description));
               }
-              drush_print_table($rows, 2);
+              drush_print_table($rows, 2, false, array(40));
               unset($rows);
               drush_print();
             }
@@ -489,32 +489,110 @@
  * @param $indent
  *   Indentation for the whole table
  * @param $header
- *   If TRUE, the first line will be treated as table
- *   header and therefore be underlined.
+ *   An array containing the headers for each column. 
+ * @param $col_widths
+ *   An array containing the number of characters each column should be.
+ *   if not specified, all the columns will have the same width, unless their
+ *   content can be displayed in fewer characters.
+ * @param $alignments
+ *   An array containing the alignment of each column. Possible options are 'left' or 'right'.
+ * 
  */
-function drush_print_table($rows, $indent = 0, $header = FALSE) {
+function drush_print_table($rows, $indent = 0, $header = FALSE, $col_widths = array(), $alignments = array()) {
   if (count($rows) == 0) {
     // Nothing to output.
     return;
   }
+  $table = new Console_Table(CONSOLE_TABLE_ALIGN_RIGHT, ' ', 0);
 
-  $indent = str_repeat(' ', $indent);
-  $format = _drush_get_table_row_format($rows);
+  if (is_array($header)) {
+    $table->setHeaders($header);
+  }
+
+  foreach ($rows as $idx => $row) {
+    $table->addRow($row, $idx);
+  }
+
+  // column width arithmatic
+  $columns = drush_get_context('DRUSH_COLUMNS', 80);
+  $widths = _drush_get_table_column_widths($rows);
+
+  $remaining = $columns - $indent - (sizeof($widths)) - 1;
+  $nowidths = array();
+
+  // populate the widths that have been specified.
+  foreach ($widths as $idx => $width) {
+    // set the appropriate alignment
+    if (!array_key_exists($idx, $alignments)) {
+      $alignments[$idx] = 'left';
+    }
 
-  $header_printed = FALSE;
-  foreach ($rows as $cols) {
-    // Print the current line.
-    print $indent . vsprintf($format, $cols) . "\n";
-    // Underline the first row if $header is set to true.
-    if (!$header_printed && $header) {
-      $headers = array();
-      foreach ($cols as $col) {
-        $headers[] = str_repeat('-', strlen($col));
+    if ($alignments[$idx] == 'left') {
+      $table->setAlign($idx, CONSOLE_COLUMN_ALIGN_LEFT);
+    }
+    else {
+      $table->setAlign($idx, CONSOLE_COLUMN_ALIGN_RIGHT);
+    }
+
+    if (array_key_exists($idx, $col_widths)) {
+      $widths[$idx] = $col_widths[$idx];
+      $remaining = $remaining - $widths[$idx];
+    }
+    else {
+      $nowidths[] = $idx;
+    }
+  }
+
+
+  if ($autocols = sizeof($nowidths)) {
+    while ($idx = current($nowidths)) {
+      $autowidth = floor($remaining / $autocols);
+      if ($widths[$idx] < $autowidth) {
+        $remaining = $remaining - $widths[$idx];
+        unset($nowidths[key($nowidths)]);
+        $autocols = sizeof($nowidths);
+        reset($nowidths);
+        continue;
       }
-      print $indent . trim(vsprintf($format, $headers)) . "\n";
-      $header_printed = TRUE;
+      else {
+        $widths[$idx] = $autowidth;
+      }
+      next($nowidths);
     }
   }
+  
+  foreach ($widths as $idx => $width) {
+    $cb[$idx] = _drush_create_filter($width, $alignments[$idx]);
+
+    $table->addFilter($idx, $cb[$idx]);
+  }
+
+  print ($table->getTable());
+  unset($table);
+  unset($cb);
+  return null;
+}
+
+function _drush_create_filter($width, $align = 'right') {
+  return create_function('&$cell', _drush_filter_template($width, $align));
+}
+
+function _drush_filter_template($width = 80, $align = 'left') {
+  $return = sprintf('
+    $align = "%s";
+  $width = %d;
+    $rows = explode("\n", wordwrap($cell, $width, "\n", TRUE));
+    foreach ($rows as $idx => $row) {
+      if ($align == "right") {
+        $rows[$idx] = str_pad($row, $width  , " ", STR_PAD_LEFT);
+      }
+      else {
+        $rows[$idx] = str_pad($row, $width , " ", STR_PAD_RIGHT);
+      }
+    }
+    $cell = implode("\n", $rows);
+    return $cell;', $align, $width);
+  return $return;
 }
 
 /**
