Format input to textual table.

@param  array $headers
@param  \Illuminate\Contracts\Support\Arrayable|array $rows
@param  string $tableStyle
@param  array $columnStyles
@return void
480989
public function table(array $headers, array $rows, $tableStyle = 'default', array $columnStyles = [])
    {
        $this->output->table($headers, $rows, $tableStyle, $columnStyles);
    }
749639
private function renderRow(RowInterface $row, Collection $columnNames)
    {
        $line = self::CHAR_CELL_SEPARATOR;

        // render cells of the row
        foreach ($columnNames as $columnName) {
            $colWidth = $this->table->getColumnWidth($columnName);
            if ($row->hasCell($columnName)) {
                $cell = $row->getCell($columnName);
                $currentCell = $this->renderCell($cell, $colWidth);
            } else {
                $currentCell = $this->renderCell(new Cell($columnName, ''), $colWidth);
            }

            $line .= $currentCell . self::CHAR_CELL_SEPARATOR;
        }

        return $line;
    }
1148712
protected function outputFormatTable($data, array $header)
    {
        if (!is_array($data)) {
            $this->line(print_r($data, true));
            $this->output();
        }

        foreach ($data as &$row) {

            if (!is_array($row)) {
                $this->errorAndExit($this->text('Unexpected table row format'));
            }

            ksort($row);

            foreach ($row as &$item) {
                if (is_array($item)) {
                    $item = '-- Array ' . count($item) . ' items --';
                }
            }
        }

        if (empty($data)) {
            $this->line($this->text('No results'));
        } else {
            array_unshift($data, $header);
            $this->table($data);
        }

        $this->output();
    }
1084749
public function render(array $columnNames, array $rows): string
	{
		if(!$this->isValidInput($columnNames, $rows))
		{
			throw new RuntimeException('The number of cells in each row must match the number of columns.');
		}

		$columnWidths = $this->getColumnWidths($columnNames, $rows);

		// Build table header

		$table = $this->buildRowSeparator($columnWidths);

		$table .= $this->buildTableRow($columnNames, $columnWidths);

		$table .= $this->buildRowSeparator($columnWidths);

		// Add table rows

		foreach($rows as $row)
		{
			$table .= $this->buildTableRow($row, $columnWidths);
		}

		// Add bottom border

		$table .= $this->buildRowSeparator($columnWidths);

		// Return table

		return $table;
	}
1345171
protected function applyStyles($row, $col, array $styles) : bool
    {
        $buffer = $this->getBuffer();

        if (!isset($buffer[$row])) {
            return false;
        }

        if (!isset($buffer[$row][$col])) {
            return false;
        }

        $current_styles = $this->buffer[$row][$col]['styles'];

        $results = [];
        foreach ($styles as $param => $value) {

            if (!isset($this->getDefaultStyles()[$param])) {
                // Apenas estilos válidos são permitidos
                throw new \InvalidArgumentException("Invalid style {$param}");
            } else {

                $border_styles = [
                    'border-top-color',
                    'border-right-color',
                    'border-bottom-color',
                    'border-left-color',
                    'border-top-style',
                    'border-right-style',
                    'border-bottom-style',
                    'border-left-style',
                ];
                // As bordas são aplicadas de forma mais complexa
                if (in_array($param, $border_styles) == true) {
                    $results[$param] = $this->applyBorderStyle($row, $col, $param, $value);
                }

                if ($value == 'none' && isset($current_styles[$param])) {
                    unset($current_styles[$param]);
                }

                if ($value != 'none') {
                    $current_styles[$param]    = $value;
                }
            }
        }

        $this->buffer[$row][$col]['styles'] = $current_styles;

        $results = array_unique($results);
        return (count($results) == 0 || current($results) === true) ? true : false;
    }
350866
public function addRow(array $row, Style $style)
    {
        $columnCount = count($row);
        $this->updateMaxColumnCount($columnCount);
        $cellXml = $this->getCellXml($row, $style);

        return $this->getRowXml($columnCount, $cellXml);
    }
468233
protected function _render(array $row, $widths, $options = [])
    {
        if (count($row) === 0) {
            return;
        }

        $out = '';
        foreach (array_values($row) as $i => $column) {
            $pad = $widths[$i] - $this->_cellWidth($column);
            if (!empty($options['style'])) {
                $column = $this->_addStyle($column, $options['style']);
            }
            $out .= '| ' . $column . str_repeat(' ', $pad) . ' ';
        }
        $out .= '|';
        $this->_io->out($out);
    }
391912
public static function columnKeys($rows)
    {
        $debug = \bdk\Debug::getInstance();
        return $debug->methodTable->colKeys($rows);
    }
377649
private function executeTableShowHeader(array $columns): void
  {
    $separator = '+';
    $header    = '|';

    foreach ($columns as $column)
    {
      $separator .= str_repeat('-', $column['length'] + 2).'+';
      $spaces    = ($column['length'] + 2) - mb_strlen((string)$column['header']);

      $spacesLeft  = (int)floor($spaces / 2);
      $spacesRight = (int)ceil($spaces / 2);

      $fillerLeft  = ($spacesLeft>0) ? str_repeat(' ', $spacesLeft) : '';
      $fillerRight = ($spacesRight>0) ? str_repeat(' ', $spacesRight) : '';

      $header .= $fillerLeft.$column['header'].$fillerRight.'|';
    }

    echo "\n", $separator, "\n";
    echo $header, "\n";
    echo $separator, "\n";
  }
1145067
public static function addDefaultCssClasses($dataArray, $rowStyles)
    {
        $count = 0;
        $ret = array();
        foreach ($dataArray as $dataItem) {
            if (!isset($dataItem['cssStyle'])) {
                $dataItem['cssClass'] = $count%2 == 0 ? 'odd' : 'even';
                $dataItem['htmlTag'] = 'td';
            } else {
                $dataItem['cssClass'] = $dataItem['cssStyle']. ' ' . ($count%2 == 0 ? 'odd' : 'even');
                $dataItem['htmlTag'] = $rowStyles[$dataItem['cssStyle']]['tag'];
            }
            for ($i = 1; $i < count($dataItem['data'])+1; $i++) {
                if (empty($dataItem['data']['column'.$i]['cssClass'])) {
                    $dataItem['data']['column'.$i]['cssClass'] .= 'col'.$i;
                } else {
                    $dataItem['data']['column'.$i]['cssClass'] .= ' col'.$i;
                }

                if ($i == 1) {
                    $dataItem['data']['column'.$i]['cssClass'] .= ' first';
                } else if ($i == count($dataItem['data'])) {
                    $dataItem['data']['column'.$i]['cssClass'] .= ' last';
                }
            }
            $ret[] = $dataItem;
            $count++;
        }
        return $ret;
    }
527712
public function processRow($row)
    {
        if (!$this->colsprinted && $this->showheaders) {
            $first = true;
            foreach ($row as $fieldName => $ignore) {
                if ($first) {
                    $first = false;
                } else {
                    $line .= ",";
                }
                $line .= $fieldName;
            }

            $this->out->write($line);
            $this->out->write(PHP_EOL);

            $line = "";
            $colsprinted = true;
        } // if show headers

        $first = true;
        foreach ($row as $columnValue) {
            if ($columnValue != null) {
                $columnValue = trim($columnValue);
            }

            if ($first) {
                $first = false;
            } else {
                $line .= $this->coldelimiter;
            }
            $line .= $columnValue;
        }

        $this->out->write($line);
        $this->out->write($this->rowdelimiter);
    }
445619
public void setText (int row, int column, Object text, int colSpan, String... styles)
    {
        setText(row, column, String.valueOf(text));
        if (colSpan > 0) {
            getFlexCellFormatter().setColSpan(row, column, colSpan);
        }
        setStyleNames(row, column, styles);
    }
1143211
public function addCols(array $cols): void
    {
        // in case of a count query we don't need to a the columns:
        if ($this->isCount === true) {
            $this->statement .= ' COUNT(*)' . PHP_EOL;
            return;
        }

        if (empty($cols)) {
            return;
        }

        foreach ($cols as $i => $col) {
            $cols[$i] = $this->quoteName($col);
        }

        $this->statement .= ' ';
        $this->statement .= implode(', ', $cols);
        $this->statement .= PHP_EOL;
    }
824302
protected function renderMarkdownTable(array $headlines, array $rows)
    {
        $lines = [];
        foreach ($headlines as $headline) {
            $lines[] = str_repeat('-', strlen($headline));
        }

        $headlines = array_map([$this, 'escapePipe'], $headlines);

        $content = '| ' . implode(' | ', $headlines) . PHP_EOL;
        $content .= '| ' . implode(' | ', $lines) . PHP_EOL;

        foreach ($rows as $row) {
            $row = array_map([$this, 'escapePipe'], $row);
            $content .= '| ' . implode(' | ', $row) . PHP_EOL;
        }

        return rtrim($content);
    }
536194
private function filterColumns(array $rows, array $header, array $columnsToDisplay)
    {
        if (empty($columnsToDisplay)) {
            return $rows;
        }

        // The available columns are all the (lower-cased) values and string
        // keys in $header.
        $availableColumns = [];
        foreach ($header as $key => $column) {
            $columnName = is_string($key) ? $key : $column;
            $availableColumns[strtolower($columnName)] = $key;
        }

        // Validate the column names.
        foreach ($columnsToDisplay as &$columnName) {
            $columnNameLowered = strtolower($columnName);
            if (!isset($availableColumns[$columnNameLowered])) {
                throw new InvalidArgumentException(
                    sprintf('Column not found: %s (available columns: %s)', $columnName, implode(', ', array_keys($availableColumns)))
                );
            }
            $columnName = $columnNameLowered;
        }

        // Filter the rows for keys matching those in $availableColumns. If a
        // key doesn't exist in a row, then the cell will be an empty string.
        $newRows = [];
        foreach ($rows as $row) {
            $newRow = [];
            foreach ($columnsToDisplay as $columnNameLowered) {
                $key = $availableColumns[$columnNameLowered];
                $newRow[] = array_key_exists($key, $row) ? $row[$key] : '';
            }
            $newRows[] = $newRow;
        }

        return $newRows;
    }
583459
public function collection(array $header, $rows): Collection
    {
        $collection = [];

        if ($rows instanceof Collection) {
            $rows = $rows->toArray();
        }

        foreach ($rows as $row) {
            $col = [];

            foreach ($header as $index => $head) {
                $col[$head] = empty($row[$index]) ? '' : $row[$index];
            }

            if (!empty($col)) {
                $collection[] = $col;
            }
        }

        return Collection::make($collection);
    }
233540
def render_table(self, headers, rows, style=None):
        
        table = self.table(headers, rows, style)

        table.render(self._io)