add possibility to render a block on command output

This commit is contained in:
Manuel Raynaud
2013-07-11 12:54:38 +02:00
parent 6baac9e36c
commit 6fa815d174
3 changed files with 45 additions and 1 deletions

3
Thelia
View File

@@ -7,6 +7,7 @@ require __DIR__ . '/core/bootstrap.php';
use Thelia\Core\Thelia;
use Thelia\Core\Application;
use Thelia\Command\Output\TheliaConsoleOutput;
use Symfony\Component\Console\Input\ArgvInput;
$input = new ArgvInput();
@@ -15,4 +16,4 @@ $debug = getenv('THELIA_DEBUG') !== '0' && !$input->hasParameterOption(array('--
$thelia = new Thelia($env, $debug);
$application = new Application($thelia);
$application->run($input);
$application->run($input, new TheliaConsoleOutput());

View File

@@ -64,6 +64,13 @@ class ModuleGenerateCommand extends ContainerAwareCommand {
$this->createDirectories();
$this->createFiles();
$output->renderBlock(array(
'',
sprintf("module %s create with success", $this->module),
"You can now configure your module and complete plugin.xml file",
''
), "bg=green;fg=black");
}
private function createDirectories()

View File

@@ -0,0 +1,36 @@
<?php
namespace Thelia\Command\Output;
use Symfony\Component\Console\Output\ConsoleOutput;
class TheliaConsoleOutput extends ConsoleOutput{
public function renderBlock(array $messages, $style = "info")
{
$strlen = function ($string) {
if (!function_exists('mb_strlen')) {
return strlen($string);
}
if (false === $encoding = mb_detect_encoding($string)) {
return strlen($string);
}
return mb_strlen($string, $encoding);
};
$length = 0;
foreach ($messages as $message) {
$length = ($strlen($message) > $length) ? $strlen($message) : $length;
}
$ouput = array();
foreach ($messages as $message) {
$output[] = "<" . $style . ">" . " " . $message . str_repeat(' ', $length - $strlen($message)) . " </" . $style . ">";
}
$this->writeln($output);
}
}