예제 #1
0
 public function testProgressMonitor4()
 {
     $out = new ezcConsoleOutput();
     $out->formats->tag->color = 'red';
     $out->formats->percent->color = 'blue';
     $out->formats->percent->style = array('bold');
     $out->formats->data->color = 'green';
     $status = new ezcConsoleProgressMonitor($out, 7, array('formatString' => $out->formatText('%2$10s', 'tag') . ' ' . $out->formatText('%1$6.2f%%', 'percent') . ' ' . $out->formatText('%3$s', 'data')));
     ob_start();
     for ($i = 0; $i < 7; $i++) {
         $status->addEntry($this->stati[$i][0], $this->stati[$i][1]);
     }
     $res = ob_get_contents();
     ob_end_clean();
     // To prepare test files use this:
     // file_put_contents( dirname( __FILE__ ) . '/data/' . ( ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/" ) . 'testProgressMonitor4.dat', $res );
     $this->assertEquals(file_get_contents(dirname(__FILE__) . '/data/' . (ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/") . 'testProgressMonitor4.dat'), $res, "Formated statusbar not generated correctly.");
 }
예제 #2
0
 /**
  * Generate a single physical row.
  * This method generates the string for a single physical table row.
  * 
  * @param array(int=>string) $cells Cells of the row.
  * @param array(int=>int) $colWidth Calculated columns widths.
  * @param ezcConsoleTableRow $row   The row to generate.
  * @return string The row.
  */
 private function generateRow($cells, $colWidth, $row)
 {
     $rowData = '';
     for ($cell = 0; $cell < count($colWidth); $cell++) {
         $align = $this->determineAlign($row, $cell);
         $format = $this->determineFormat($row, $cell);
         $borderFormat = $this->determineBorderFormat($row);
         $data = isset($cells[$cell]) ? $cells[$cell] : '';
         $rowData .= $this->outputHandler->formatText($this->properties['options']->lineHorizontal, $borderFormat);
         $rowData .= $this->properties['options']->colPadding;
         $rowData .= $this->outputHandler->formatText(str_pad($data, $colWidth[$cell], ' ', $align), $format);
         $rowData .= $this->properties['options']->colPadding;
     }
     $rowData .= $this->outputHandler->formatText($this->properties['options']->lineHorizontal, $row->borderFormat);
     return $rowData;
 }
예제 #3
0
 public function testProgress9()
 {
     $out = new ezcConsoleOutput();
     $formatString = '' . $out->formatText('Actual progress', 'success') . ': <' . $out->formatText('%bar%', 'failure') . '> ' . $out->formatText('%fraction%', 'success');
     $this->commonProgressbarTest(__FUNCTION__, 1073, 123, array('barChar' => '123', 'emptyChar' => '987', 'progressChar' => '---', 'width' => 97, 'formatString' => $formatString, 'fractionFormat' => '%o'));
 }
예제 #4
0
require_once 'Base/src/base.php';
/**
 * Autoload ezc classes 
 * 
 * @param string $className 
 */
function __autoload($className)
{
    ezcBase::autoload($className);
}
$out = new ezcConsoleOutput();
$out->formats->red->color = "red";
// Create progress bar itself
$progress = new ezcConsoleProgressbar($out, 100, array('step' => 5));
$progress->options->emptyChar = '-';
$progress->options->progressChar = $out->formatText('>', "red");
$progress->options->formatString = "Uploading file </tmp/foobar.tar.bz2>: %act%/%max% kb [%bar%]";
// Perform actions
$i = 0;
while ($i++ < 20) {
    // Do whatever you want to indicate progress for
    usleep(mt_rand(20000, 2000000));
    // Advance the progressbar by one step ( uploading 5k per run )
    $progress->advance();
}
// Finish progress bar and jump to next line.
$progress->finish();
$out->outputText("Successfully uploaded </tmp/foobar.tar.bz2>.\n", 'success');
/*
OUTPUT: (sequential, will be printed into 1 line and updated in reallife)
Uploading file </tmp/foobar.tar.bz2>:   5/100 kb [++#----------------------------------------------]
예제 #5
0
 /**
  * Returns the given $text formatted with $format.
  *
  * In case $useFormats is set to false in the output handler, the text is 
  * returned as given, without any formatting.
  * 
  * @param string $text 
  * @param string $format 
  * @return string
  */
 private function formatText($text, $format)
 {
     if ($this->outputHandler->options->useFormats) {
         return $this->outputHandler->formatText($text, $format);
     } else {
         return $text;
     }
 }
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->success->color = 'green';
$output->formats->failure->color = 'red';
$options = array('successChar' => $output->formatText('+', 'success'), 'failureChar' => $output->formatText('-', 'failure'));
$status = new ezcConsoleStatusbar($output, $options);
for ($i = 0; $i < 120; $i++) {
    $nextStatus = (bool) mt_rand(0, 1);
    $status->add($nextStatus);
    usleep(mt_rand(200, 2000));
}
$output->outputLine();
$output->outputLine('Successes: ' . $status->getSuccessCount() . ', Failures: ' . $status->getFailureCount());
<?php

require 'ezc-setup.php';
$max = 23;
$output = new ezcConsoleOutput();
$output->formats->bar->color = 'red';
$output->formats->bar->style = array('bold');
$options = array('emptyChar' => ' ', 'barChar' => '-', 'formatString' => '%act% / %max% [' . $output->formatText('%bar%', 'bar') . '] %fraction%%');
$progress = new ezcConsoleProgressbar($output, $max, $options);
for ($i = 0; $i < $max; $i++) {
    usleep(20000);
    $progress->advance();
}
$progress->finish();
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->bar->color = 'blue';
$output->formats->bar->style = array('bold');
$options = array('emptyChar' => ' ', 'barChar' => '-', 'formatString' => '%fraction%% <' . $output->formatText('%bar%', 'bar') . '> Uploaded %act% / %max% kb', 'redrawFrequency' => 50);
$bar = new ezcConsoleProgressbar($output, 1024, $options);
for ($i = 0; $i < 1024; $i++) {
    $bar->advance();
    usleep(mt_rand(200, 2000));
}
$bar->finish();
$output->outputLine();