public function testNonBorderedTableWithoutHeader()
    {
        $nonBorderedTableWithoutHeader = '
 PHP  1994 
 C++  1983 
 C    1970 ';
        $table = new ConsoleTable();
        $table->addRow(array('PHP', 1994))->addRow(array('C++', 1983))->addRow(array('C', 1970))->hideBorder();
        $this->assertEquals(trim($nonBorderedTableWithoutHeader), trim($table->getTable()));
    }
Esempio n. 2
0
<?php

require 'src/LucidFrame/Console/ConsoleTable.php';
use LucidFrame\Console\ConsoleTable;
function _pr($string)
{
    if (PHP_SAPI == 'cli') {
        echo "\n";
        echo '### ' . $string . ' ###';
        echo "\n\n";
    } else {
        echo '<h2>' . $string . '</h2>';
    }
}
_pr('Bordered Table (Default)');
$table = new ConsoleTable();
$table->addHeader('Language')->addHeader('Year')->addRow()->addColumn('PHP')->addColumn(1994)->addRow()->addColumn('C++')->addColumn(1983)->addRow()->addColumn('C')->addColumn(1970)->display();
_pr('Bordered Table with Padding Width 2');
$table = new ConsoleTable();
$table->setHeaders(array('Language', 'Year'))->addRow(array('PHP', 1994))->addRow(array('C++', 1983))->addRow(array('C', 1970))->setPadding(2)->display();
_pr('Bordered Table with Left Margin Width 4');
$table = new ConsoleTable();
$table->setHeaders(array('Language', 'Year'))->addRow(array('PHP', 1994))->addRow(array('C++', 1983))->addRow(array('C', 1970))->setIndent(4)->display();
_pr('Non-bordered Table with Header');
$table = new ConsoleTable();
$table->setHeaders(array('Language', 'Year'))->addRow(array('PHP', 1994))->addRow(array('C++', 1983))->addRow(array('C', 1970))->hideBorder()->display();
_pr('Non-bordered Table without Header');
$table = new ConsoleTable();
$table->addRow(array('PHP', 1994))->addRow(array('C++', 1983))->addRow(array('C', 1970))->hideBorder()->display();
Esempio n. 3
0
 /**
  * Display the help message
  * @return void
  */
 public function showHelp()
 {
     $options = $this->getOptions();
     if (count($options)) {
         _writeln('Usage:');
         $usage = _indent() . $this->name . ' [options]';
         if (count($this->arguments)) {
             $usage .= ' [<' . implode('>] [<', $this->argumentNames) . '>]';
         }
         _writeln($usage);
         # Arguments
         if (count($this->arguments)) {
             _writeln();
             _writeln('Arguments:');
             $table = new ConsoleTable();
             $table->hideBorder()->setPadding(2);
             foreach ($this->arguments as $arg) {
                 $table->addRow();
                 $table->addColumn($arg['name']);
                 $desc = $arg['description'];
                 if ($arg['default']) {
                     $desc .= ' [default: "' . $arg['default'] . '"]';
                 }
                 $table->addColumn($desc);
             }
             $table->display();
         }
         # Options
         if (count($options)) {
             _writeln();
             _writeln('Options:');
             $table = new ConsoleTable();
             $table->hideBorder()->setPadding(2);
             foreach ($this->options as $name => $opt) {
                 $table->addRow();
                 $table->addColumn($opt['key']);
                 $desc = $opt['description'];
                 if ($opt['default']) {
                     $desc .= ' [default: "' . $opt['default'] . '"]';
                 }
                 $table->addColumn($desc);
             }
             $table->display();
         }
         if ($this->description) {
             _writeln();
             _writeln('Help:');
             _writeln(_indent() . $this->description);
         }
     }
 }