Permalink
Browse files

[2.3] [Console] TableHelper

  • Loading branch information...
1 parent e8b7f0f commit 8de7813cab9e9d134bebf01a2bed44100aac1d39 @umpirsky umpirsky committed with fabpot Dec 15, 2012
@@ -27,6 +27,7 @@
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\ProgressHelper;
+use Symfony\Component\Console\Helper\TableHelper;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleForExceptionEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
@@ -1013,6 +1014,7 @@ protected function getDefaultHelperSet()
new FormatterHelper(),
new DialogHelper(),
new ProgressHelper(),
+ new TableHelper(),
));
}
@@ -4,6 +4,7 @@ CHANGELOG
2.3.0
-----
+ * added Table Helper for tabular data rendering
* added support for events in `Application`
* added a way to normalize EOLs in `ApplicationTester::getDisplay()` and `CommandTester::getDisplay()`
* added a way to set the progress bar progress via the `setCurrent` method
@@ -71,26 +71,6 @@ public function formatBlock($messages, $style, $large = false)
}
/**
- * Returns the length of a string, using mb_strlen if it is available.
- *
- * @param string $string The string to check its length
- *
- * @return integer The length of the string
- */
- private function strlen($string)
- {
- if (!function_exists('mb_strlen')) {
- return strlen($string);
- }
-
- if (false === $encoding = mb_detect_encoding($string)) {
- return strlen($string);
- }
-
- return mb_strlen($string, $encoding);
- }
-
- /**
* {@inheritDoc}
*/
public function getName()
@@ -39,4 +39,24 @@ public function getHelperSet()
{
return $this->helperSet;
}
+
+ /**
+ * Returns the length of a string, using mb_strlen if it is available.
+ *
+ * @param string $string The string to check its length
+ *
+ * @return integer The length of the string
+ */
+ protected function strlen($string)
+ {
+ if (!function_exists('mb_strlen')) {
+ return strlen($string);
+ }
+
+ if (false === $encoding = mb_detect_encoding($string)) {
+ return strlen($string);
+ }
+
+ return mb_strlen($string, $encoding);
+ }
}
@@ -14,7 +14,7 @@
use Symfony\Component\Console\Output\OutputInterface;
/**
- * The Progress class providers helpers to display progress output.
+ * The Progress class provides helpers to display progress output.
*
* @author Chris Jones <leeked@gmail.com>
* @author Fabien Potencier <fabien@symfony.com>
@@ -320,7 +320,7 @@ private function initialize()
}
if ($this->max > 0) {
- $this->widths['max'] = $this->getLength($this->max);
+ $this->widths['max'] = $this->strlen($this->max);
$this->widths['current'] = $this->widths['max'];
} else {
$this->barCharOriginal = $this->barChar;
@@ -356,7 +356,7 @@ private function generate($finish = false)
}
}
- $emptyBars = $this->barWidth - $completeBars - $this->getLength($this->progressChar);
+ $emptyBars = $this->barWidth - $completeBars - $this->strlen($this->progressChar);
$bar = str_repeat($this->barChar, $completeBars);
if ($completeBars < $this->barWidth) {
$bar .= $this->progressChar;
@@ -419,7 +419,7 @@ private function humaneTime($secs)
*/
private function overwrite(OutputInterface $output, $message)
{
- $length = $this->getLength($message);
+ $length = $this->strlen($message);
// append whitespace to match the last line's length
if (null !== $this->lastMessagesLength && $this->lastMessagesLength > $length) {
@@ -430,26 +430,7 @@ private function overwrite(OutputInterface $output, $message)
$output->write("\x0D");
$output->write($message);
- $this->lastMessagesLength = $this->getLength($message);
- }
-
- /**
- * Wrapper arround strlen: uses multi-byte function if available
- *
- * @param string $string
- * @return integer
- */
- private function getLength($string)
- {
- if (!function_exists('mb_strlen')) {
- return strlen($string);
- }
-
- if (false === $encoding = mb_detect_encoding($string)) {
- return strlen($string);
- }
-
- return mb_strlen($string, $encoding);
+ $this->lastMessagesLength = $this->strlen($message);
}
/**
Oops, something went wrong.

0 comments on commit 8de7813

Please sign in to comment.