示例#1
0
 public function testAnsiColorsAndEmojis()
 {
     $bar = new ProgressBar($output = $this->getOutputStream(), 15);
     ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
         static $i = 0;
         $mem = 100000 * $i;
         $colors = $i++ ? '41;37' : '44;37';
         return "[" . $colors . "m " . Helper::formatMemory($mem) . " ";
     });
     $bar->setFormat("  %title:-37s% \n %current%/%max% %bar% %percent:3s%%\n 🏁  %remaining:-10s% %memory:37s%");
     $bar->setBarCharacter($done = "●");
     $bar->setEmptyBarCharacter($empty = "●");
     $bar->setProgressCharacter($progress = "➤ ");
     $bar->setMessage('Starting the demo... fingers crossed', 'title');
     $bar->start();
     $bar->setMessage('Looks good to me...', 'title');
     $bar->advance(4);
     $bar->setMessage('Thanks, bye', 'title');
     $bar->finish();
     rewind($output->getStream());
     $this->assertEquals($this->generateOutput("  Starting the demo... fingers crossed  \n" . "  0/15 " . $progress . str_repeat($empty, 26) . "   0%\n" . " 🏁  1 sec                           0 B ") . $this->generateOutput("  Looks good to me...                   \n" . "  4/15 " . str_repeat($done, 7) . $progress . str_repeat($empty, 19) . "  26%\n" . " 🏁  1 sec                        97 KiB ") . $this->generateOutput("  Thanks, bye                           \n" . " 15/15 " . str_repeat($done, 28) . " 100%\n" . " 🏁  1 sec                       195 KiB "), stream_get_contents($output->getStream()));
 }
示例#2
0
 private static function initPlaceholderFormatters()
 {
     return array('bar' => function (ProgressBar $bar, OutputInterface $output) {
         $completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth());
         $display = str_repeat($bar->getBarCharacter(), $completeBars);
         if ($completeBars < $bar->getBarWidth()) {
             $emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
             $display .= $bar->getProgressCharacter() . str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
         }
         return $display;
     }, 'elapsed' => function (ProgressBar $bar) {
         return Helper::formatTime(time() - $bar->getStartTime());
     }, 'remaining' => function (ProgressBar $bar) {
         if (!$bar->getMaxSteps()) {
             throw new \LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
         }
         if (!$bar->getProgress()) {
             $remaining = 0;
         } else {
             $remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
         }
         return Helper::formatTime($remaining);
     }, 'estimated' => function (ProgressBar $bar) {
         if (!$bar->getMaxSteps()) {
             throw new \LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
         }
         if (!$bar->getProgress()) {
             $estimated = 0;
         } else {
             $estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
         }
         return Helper::formatTime($estimated);
     }, 'memory' => function (ProgressBar $bar) {
         return Helper::formatMemory(memory_get_usage(true));
     }, 'current' => function (ProgressBar $bar) {
         return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
     }, 'max' => function (ProgressBar $bar) {
         return $bar->getMaxSteps();
     }, 'percent' => function (ProgressBar $bar) {
         return floor($bar->getProgressPercent() * 100);
     });
 }
示例#3
0
文件: Table.php 项目: Danack/Console
 /**
  * Gets cell width.
  *
  * @param array   $row
  * @param int     $column
  *
  * @return int
  */
 private function getCellWidth(array $row, $column)
 {
     return isset($row[$column]) ? Helper::strlenWithoutDecoration($this->output->getFormatter(), $row[$column]) : 0;
 }