From d93b16f407b742cf3205f1a01d41ae2732df57d5 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Wed, 3 Jun 2015 10:47:06 +0000 Subject: [PATCH] [console][TableCell] get cell width without decoration. --- src/Symfony/Component/Console/Helper/Table.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index ff668a475e..392d4652ef 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -385,7 +385,7 @@ class Table $unmergedRows = array(); foreach ($rows[$line] as $column => $cell) { if ($cell instanceof TableCell && $cell->getRowspan() > 1) { - $nbLines = $cell->getRowspan()-1; + $nbLines = $cell->getRowspan() - 1; $lines = array($cell); if (strstr($cell, "\n")) { $lines = explode("\n", $cell); @@ -412,7 +412,7 @@ class Table array_splice($rows[$unmergedRowKey], $cellKey, 0, array($cell)); } } else { - $row = $this->copyRow($rows, $unmergedRowKey-1); + $row = $this->copyRow($rows, $unmergedRowKey - 1); foreach ($unmergedRow as $column => $cell) { if (!empty($cell)) { $row[$column] = $unmergedRow[$column]; @@ -476,7 +476,7 @@ class Table { $columns = count($row); foreach ($row as $column) { - $columns += $column instanceof TableCell ? ($column->getColspan()-1) : 0; + $columns += $column instanceof TableCell ? ($column->getColspan() - 1) : 0; } return $columns; @@ -491,11 +491,11 @@ class Table */ private function getRowColumns($row) { - $columns = range(0, $this->numberOfColumns-1); + $columns = range(0, $this->numberOfColumns - 1); foreach ($row as $cellKey => $cell) { if ($cell instanceof TableCell && $cell->getColspan() > 1) { // exclude grouped columns. - $columns = array_diff($columns, range($cellKey+1, $cellKey + $cell->getColspan()-1)); + $columns = array_diff($columns, range($cellKey + 1, $cellKey + $cell->getColspan() - 1)); } } @@ -550,12 +550,13 @@ class Table { if (isset($row[$column])) { $cell = $row[$column]; + $cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell); if ($cell instanceof TableCell && $cell->getColspan() > 1) { // we assume that cell value will be across more than one column. - $cell = substr($cell, 0, strlen($cell)/$cell->getColspan()); + $cellWidth = $cellWidth / $cell->getColspan(); } - return Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell); + return $cellWidth; } return 0;