add possibility to render a block on command output
This commit is contained in:
3
Thelia
3
Thelia
@@ -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());
|
||||
@@ -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()
|
||||
|
||||
36
core/lib/Thelia/Command/Output/TheliaConsoleOutput.php
Normal file
36
core/lib/Thelia/Command/Output/TheliaConsoleOutput.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user