Esempio n. 1
0
 /**
  *
  * {@inheritDoc}
  *
  * @see \SK\ITCBundle\Service\Table\Adapter\IAdapter::write()
  */
 public function write(Table $table, OutputInterface $output)
 {
     $style = new TableStyle();
     $style->setHorizontalBorderChar('<fg=magenta>-</>')->setVerticalBorderChar('<fg=magenta>|</>')->setCrossingChar('<fg=magenta>+</>');
     $stable = new STable($output);
     $stable->setStyle('default');
     $stable->setHeaders($table->getHeaders());
     $columns = $table->getColumns();
     $colspan = count($columns);
     $rows = $table->getRows();
     foreach ($rows as $row) {
         $rowModificated = [];
         foreach ($columns as $iCol => $col) {
             if (is_int($iCol)) {
                 $iCol = $col;
             }
             if (array_key_exists($iCol, $row)) {
                 $rowModificated[$iCol] = wordwrap($row[$iCol], $table->getMaxColWidth(), "\n", true);
             } else {
                 $rowModificated[$iCol] = "";
             }
         }
         $stable->addRow($rowModificated);
         $stable->addRow(array(new TableSeparator(array('colspan' => $colspan))));
     }
     $stable->addRow(array(new TableCell("", array('colspan' => $colspan))));
     $stable->addRow(array(new TableCell(sprintf("Found %s results.", count($rows)), array('colspan' => $colspan))));
     $stable->render();
 }
Esempio n. 2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $lists = $this->rfcService->getLists([RfcService::IN_VOTING]);
     $rfcs = array_pop($lists);
     $table = new Table($output);
     $voteStyle = new TableStyle();
     $voteStyle->setCellRowFormat('<comment>%s</comment>');
     $rfcStyle = new TableStyle();
     $rfcStyle->setCellRowFormat('<info>%s</info>');
     foreach ($rfcs as $i => $rfcDetails) {
         $rfcCode = $rfcDetails[1];
         // Build RFC
         $rfc = $this->rfcService->getRfc($rfcCode);
         $table->addRow([$rfcDetails[0]], $rfcStyle);
         $table->addRow(new TableSeparator());
         foreach ($rfc->getVotes() as $title => $vote) {
             $table->addRow([$title], $voteStyle);
             array_shift($vote['counts']);
             foreach ($vote['counts'] as $key => $total) {
                 $table->addRow([$key, $total]);
             }
         }
         if ($rfcDetails !== end($rfcs)) {
             $table->addRow(new TableSeparator());
         }
     }
     $table->render();
 }
 /**
  * Calculate our padding widths from the specified table style.
  * @param TableStyle $style
  */
 public function setPaddingFromStyle(TableStyle $style)
 {
     $verticalBorderLen = strlen(sprintf($style->getBorderFormat(), $style->getVerticalBorderChar()));
     $paddingLen = strlen($style->getPaddingChar());
     $this->extraPaddingAtBeginningOfLine = 0;
     $this->extraPaddingAtEndOfLine = $verticalBorderLen;
     $this->paddingInEachCell = $verticalBorderLen + $paddingLen + 1;
 }
Esempio n. 4
0
 private function declareWinner(PokerGame $pokerGame)
 {
     $style = new TableStyle();
     $style->setVerticalBorderChar('<fg=red;bg=black>|</>')->setHorizontalBorderChar('<fg=red;bg=black>-</>');
     $winningHand = $pokerGame->getWinner();
     $table = new Table($this->output);
     $table->setRows([$winningHand]);
     $table->render();
 }
 /**
  * {@inheritdoc}
  */
 public function table(array $headers, array $rows)
 {
     $headers = array_map(function ($value) {
         return sprintf("<info>%s</info>", $value);
     }, $headers);
     $styleGuide = new TableStyle();
     $styleGuide->setHorizontalBorderChar('-')->setVerticalBorderChar('|')->setCrossingChar('+')->setCellHeaderFormat('%s');
     $table = new Table($this);
     $table->setHeaders($headers);
     $table->setRows($rows);
     $table->setStyle($styleGuide);
     $table->render();
     $this->newLine();
 }
Esempio n. 6
0
 public function displayTableResults(OutputInterface $output, $object, array $keysOnly = [], $maxWidth = 35, $count = false)
 {
     $table = new Table($output);
     $style = new TableStyle();
     $style->setHorizontalBorderChar('<fg=magenta>-</>')->setVerticalBorderChar('<fg=magenta>|</>')->setCrossingChar(' ');
     $table->setStyle($style);
     if ($object instanceof CollectionAbstract) {
         $list = $object->toArray();
     } else {
         $list = $object;
     }
     $i = 0;
     foreach ($list as $item) {
         if (!is_array($item)) {
             continue;
         }
         ++$i;
         foreach ($item as $key => $value) {
             if (!empty($keysOnly) && !in_array($key, $keysOnly, true)) {
                 unset($item[$key]);
                 continue;
             }
             if (is_array($value)) {
                 $value = json_encode($value);
             }
             if (is_float($value)) {
                 $value = number_format($value, 3);
             }
             $value = str_replace(['["', '"]', '{"', '"', '}'], [], $value);
             if (empty($value)) {
                 $value = '~';
             }
             $value = substr($value, 0, $maxWidth);
             $item[$key] = $value;
         }
         if (true === $count) {
             $item = array_merge(['#' => $i], $item);
         }
         if (!isset($headers)) {
             $headers = array_keys($item);
             $table->setHeaders($headers);
         }
         $table->addRow($item);
     }
     return $table->render($output);
 }
Esempio n. 7
0
 /**
  * {@inheritDoc}
  */
 protected function doExecute()
 {
     $table = new Table($this->output);
     $table->setHeaders(['Name', 'Description']);
     $style = new TableStyle();
     $style->setCellHeaderFormat('<fg=red>%s</fg=red>');
     $style->setCellRowFormat('<fg=blue>%s</fg=blue>');
     $style->setBorderFormat('<fg=yellow>%s</fg=yellow>');
     $table->setStyle($style);
     /** @type AbstractTask[] $services */
     $services = $this->container->get('bldr.registry.task')->findAll();
     foreach ($services as $service) {
         if ($service instanceof AbstractTask) {
             $service->configure();
         }
         $table->addRow([$service->getName(), $service->getDescription() !== '' ? $service->getDescription() : 'No Description']);
     }
     $table->render($this->output);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $message = $formatter->formatSection('Section', 'Hello!', 'comment');
     $output->writeln($message);
     $blockMessage = $formatter->formatBlock(['Good luck!'], 'bg=black;fg=white', true);
     $output->writeln($blockMessage);
     /** @var ProcessHelper $processHelper */
     $processHelper = $this->getHelper('process');
     $process = ProcessBuilder::create(['figlet', 'Started!'])->getProcess();
     $processHelper->run($output, $process, 'Something went wrong');
     $finder = new Finder();
     $files = $finder->in(CACHE_PATH)->name('makes*json')->files();
     $progressHelper = new ProgressBar($output);
     $progressHelper->setEmptyBarCharacter('.');
     $progressHelper->setBarCharacter('<comment>+</comment>');
     if ($input->getOption('progress')) {
         $progressHelper->start($files->count());
     }
     $table = new Table($output);
     $table->setStyle('default');
     $style = new TableStyle();
     $style->setBorderFormat('<comment>%s</comment>');
     $table->setStyle($style);
     foreach ($files as $file) {
         /** @var SplFileInfo $file */
         $makes = json_decode($file->getContents(), true);
         $table->setHeaders(['Make Name', 'Models Count']);
         foreach ($makes['makes'] as $make) {
             $table->addRow([$make['name'], count($make['models'])]);
         }
         //            $table->render($output);
         if ($input->getOption('progress')) {
             $progressHelper->advance();
         }
     }
     if ($input->getOption('progress')) {
         $progressHelper->finish();
         $output->writeln('');
     }
 }
Esempio n. 9
0
 /**
  * Renders table cell with padding.
  *
  * @param array  $row
  * @param int    $column
  * @param string $cellFormat
  */
 private function renderCell(array $row, $column, $cellFormat)
 {
     $cell = isset($row[$column]) ? $row[$column] : '';
     $width = $this->getColumnWidth($column);
     // str_pad won't work properly with multi-byte strings, we need to fix the padding
     if (function_exists('mb_strwidth') && false !== ($encoding = mb_detect_encoding($cell))) {
         $width += strlen($cell) - mb_strwidth($cell, $encoding);
     }
     $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
     $content = sprintf($this->style->getCellRowContentFormat(), $cell);
     $this->output->write(sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType())));
 }
Esempio n. 10
0
 /**
  * Execute Command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $sections = ['voting' => RfcService::IN_VOTING, 'discussion' => RfcService::DISCUSSION, 'draft' => RfcService::DRAFT, 'accepted' => RfcService::ACCEPTED, 'declined' => RfcService::DECLINED, 'withdrawn' => RfcService::WITHDRAWN, 'inactive' => RfcService::INACTIVE];
     $sections = array_intersect_key($sections, array_filter($input->getOptions()));
     if (count($sections) === 0 && !$input->getOption('all')) {
         $sections[] = RfcService::IN_VOTING;
     }
     $table = new Table($output);
     $titleStyle = new TableStyle();
     $titleStyle->setCellRowFormat('<comment>%s</comment>');
     $lists = $this->rfcService->getLists($sections);
     $table->setHeaders(['RFC', 'RFC Code']);
     foreach ($lists as $heading => $list) {
         $table->addRow([$heading], $titleStyle);
         $table->addRow(new TableSeparator());
         foreach ($list as $listing) {
             $table->addRow($listing);
         }
         if ($list !== end($lists)) {
             $table->addRow(new TableSeparator());
         }
     }
     $table->render();
 }
Esempio n. 11
0
 /**
  * {@inheritDoc}
  */
 protected function doExecute()
 {
     /** @type AbstractTask $service */
     $service = $this->container->get('bldr.registry.task')->findTaskByType($this->input->getArgument('task'));
     $this->output->writeln('');
     $this->output->writeln('<fg=green>Task Name</fg=green>: ' . $service->getName());
     if ($service->getDescription() !== null) {
         $this->output->writeln('<fg=green>Task Description</fg=green>: ' . $service->getDescription());
     }
     if ($service instanceof AbstractTask) {
         $this->output->writeln(['', '<fg=green>Options:</fg=green>']);
         $tableHelper = new Table($this->output);
         $style = new TableStyle();
         $style->setCellHeaderFormat('<fg=red>%s</fg=red>');
         $style->setCellRowFormat('<fg=blue>%s</fg=blue>');
         $style->setBorderFormat('<fg=yellow>%s</fg=yellow>');
         $tableHelper->setStyle($style);
         $tableHelper->setHeaders(['Option', 'Description', 'Required', "Default"]);
         foreach ($service->getParameterDefinition() as $option) {
             $tableHelper->addRow([$option['name'], $option['description'] !== '' ? $option['description'] : 'No Description', $option['required'] ? 'Yes' : 'No', json_encode($option['default'])]);
         }
         $tableHelper->render();
     }
 }
Esempio n. 12
0
 /**
  * Display validation errors.
  *
  * @param Validator       $validator The json-schema validator.
  * @param OutputInterface $output    An OutputInterface instance.
  */
 public static function displayErrors(Validator $validator, OutputInterface $output)
 {
     $table = new Table($output);
     $style = new TableStyle();
     $style->setCellHeaderFormat('<error>%s</error>');
     $style->setHorizontalBorderChar(' ');
     $style->setVerticalBorderChar(' ');
     $style->setCrossingChar(' ');
     $table->setHeaders(['Property', 'Error']);
     $table->setRows($validator->getErrors());
     $table->setStyle($style);
     $table->render();
 }
Esempio n. 13
0
 private static function initStyles()
 {
     $borderless = new TableStyle();
     $borderless->setHorizontalBorderChar('=')->setVerticalBorderChar(' ')->setCrossingChar(' ');
     $compact = new TableStyle();
     $compact->setHorizontalBorderChar('')->setVerticalBorderChar(' ')->setCrossingChar('')->setCellRowContentFormat('%s');
     $styleGuide = new TableStyle();
     $styleGuide->setHorizontalBorderChar('-')->setVerticalBorderChar(' ')->setCrossingChar(' ')->setCellHeaderFormat('%s');
     return array('default' => new TableStyle(), 'borderless' => $borderless, 'compact' => $compact, 'symfony-style-guide' => $styleGuide);
 }
Esempio n. 14
0
    public function testColumnStyle()
    {
        $table = new Table($output = $this->getOutputStream());
        $table->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))->setRows(array(array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri', '9.95'), array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25')));
        $style = new TableStyle();
        $style->setPadType(STR_PAD_LEFT);
        $table->setColumnStyle(3, $style);
        $table->render();
        $expected = <<<TABLE
+---------------+----------------------+-----------------+--------+
| ISBN          | Title                | Author          |  Price |
+---------------+----------------------+-----------------+--------+
| 99921-58-10-7 | Divine Comedy        | Dante Alighieri |   9.95 |
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | 139.25 |
+---------------+----------------------+-----------------+--------+

TABLE;
        $this->assertEquals($expected, $this->getOutputContent($output));
    }
Esempio n. 15
0
    public function testStyle()
    {
        $style = new TableStyle();
        $style->setHorizontalBorderChar('.')->setVerticalBorderChar('.')->setCrossingChar('.');
        Table::setStyleDefinition('dotfull', $style);
        $table = new Table($output = $this->getOutputStream());
        $table->setHeaders(array('Foo'))->setRows(array(array('Bar')))->setStyle('dotfull');
        $table->render();
        $expected = <<<TABLE
            .......
. Foo .
.......
. Bar .
.......

TABLE;
        $this->assertEquals($expected, $this->getOutputContent($output));
    }
Esempio n. 16
0
 /**
  * Get a Table instance.
  *
  * Falls back to legacy TableHelper.
  *
  * @return Table|TableHelper
  */
 protected function getTable(OutputInterface $output)
 {
     if (!class_exists('Symfony\\Component\\Console\\Helper\\Table')) {
         return $this->getTableHelper();
     }
     $style = new TableStyle();
     $style->setVerticalBorderChar(' ')->setHorizontalBorderChar('')->setCrossingChar('');
     $table = new Table($output);
     return $table->setRows(array())->setStyle($style);
 }
 /**
  * @param string[] $rows
  * @param string[] $headers
  */
 public function table(array $rows, array $headers = null)
 {
     $rows = array_map(function ($value) {
         if (!is_array($value)) {
             return $value;
         }
         $header = array_shift($value);
         array_unshift($value, sprintf('<fg=blue>%s</>', $header));
         return $value;
     }, $rows);
     $style = new TableStyle();
     $style->setVerticalBorderChar('<fg=blue>|</>');
     $style->setHorizontalBorderChar('<fg=blue>-</>');
     $style->setCrossingChar('<fg=blue>+</>');
     $style->setCellHeaderFormat('%s');
     $table = new Table($this);
     $table->setStyle($style);
     if ($headers) {
         $table->setHeaders($headers);
     }
     $table->setRows($rows);
     $table->render();
     $this->newLine();
 }
Esempio n. 18
0
 /**
  * Gets column width.
  *
  * @return int
  */
 private function getColumnSeparatorWidth()
 {
     return strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
 }
Esempio n. 19
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Invalid padding type.
  * Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).
  */
 public function testSetPadTypeWithInvalidType()
 {
     $style = new TableStyle();
     $style->setPadType('TEST');
 }
 /**
  * Add our custom table style(s) to the table.
  */
 protected static function addCustomTableStyles($table)
 {
     // The 'consolidation' style is the same as the 'symfony-style-guide'
     // style, except it maintains the colored headers used in 'default'.
     $consolidationStyle = new TableStyle();
     $consolidationStyle->setHorizontalBorderChar('-')->setVerticalBorderChar(' ')->setCrossingChar(' ');
     $table->setStyleDefinition('consolidation', $consolidationStyle);
 }
Esempio n. 21
0
 protected static function initStyles()
 {
     $borderless = new TableStyle();
     $borderless->setHorizontalBorderChar('=')->setVerticalBorderChar(' ')->setCrossingChar(' ');
     $compact = new TableStyle();
     $compact->setHorizontalBorderChar('')->setVerticalBorderChar(' ')->setCrossingChar('')->setCellRowContentFormat('%s');
     return array('default' => new TableStyle(), 'borderless' => $borderless, 'compact' => $compact);
 }