Skip to content

Commit

Permalink
Show timer just before all message is enabled & updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Adamiak committed May 4, 2019
1 parent e66ac8d commit 8c73819
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
46 changes: 42 additions & 4 deletions examples/style.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,45 @@
$style->warningMessage('Alignment 15');

$message = 'This is a very long message, which should be truncated';
$style->truncateln($message, 7);
$style->truncateln($message, -5);
$style->truncateln($message, 7, '!!');
$style->truncateln('Short', 10);
$style->truncateLn($message, 7);
$style->truncateLn($message, -5);
$style->truncateLn($message, 7, '!!');
$style->truncateLn('Short', 10);

//timer display enable
$style->newLine(4);

$style->toggleShowTimer();

$style->timer();

$style->warningMessage('Warning message with timer');
$style->errorMessage('Error message with timer');
$style->okMessage('Ok message with timer');
$style->infoMessage('Info message with timer');

$style->newLine(2);
$style->error('Error with timer');
$style->note('Note with timer');
$style->warning('Warning with timer');
$style->caution('Caution with timer');
$style->success('Success with timer');

$style->genericBlock('Generic block success', 'blue', 'success', 50);
$style->genericBlock('Generic block success', 'blue', '', 50);

$style->formatBlock(['Error 1', 'Error 2'], 'error');
$style->formatBlock(['Error 1', 'Error 2'], 'info');
$style->errorLine(['Error Line']);

$style->formatSection('Section', 'Format Section info (default)');
$style->formatSection('Section', 'Format Section error', 'error');
$style->formatSection('Section', 'Format Section comment', 'comment');
$style->formatSection('Section', 'Format Section question', 'question');

$style->setAlign(5);
$style->infoMessage('Alignment 5');
$style->setAlign(10);
$style->okMessage('Alignment 10');
$style->setAlign(15);
$style->warningMessage('Alignment 15');
40 changes: 26 additions & 14 deletions src/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public function timer(bool $newLine = true): self
* @throws \InvalidArgumentException
* @return $this
*/
public function formatSection($section, $message, $style = 'info') : self
public function formatSection(string $section, string $message, string $style = 'info') : self
{
$timer = $this->getTimer(true);

$this->writeln(
$this->formatter->formatSection(
$timer . $this->formatter->formatSection(
$section,
$message,
$style
Expand All @@ -52,15 +54,23 @@ public function formatSection($section, $message, $style = 'info') : self
* @throws \InvalidArgumentException
* @return $this
*/
public function formatBlock($messages, $style, $large = false) : self
public function formatBlock($messages, string $style, $large = false) : self
{
$this->writeln(
$this->formatter->formatBlock(
$messages,
$style,
$large
)
);
$timer = $this->getTimer(true);

if (!\is_array($messages)) {
$messages = [$messages];
}

foreach ($messages as $message) {
$this->writeln(
$timer . $this->formatter->formatBlock(
$message,
$style,
$large
)
);
}

return $this;
}
Expand All @@ -80,7 +90,7 @@ public function errorLine(array $message) : self
* @return $this
* @throws \InvalidArgumentException
*/
public function okMessage($message) : self
public function okMessage(string $message) : self
{
return $this->renderBlock(' <info>OK</info> ', $message);
}
Expand All @@ -90,7 +100,7 @@ public function okMessage($message) : self
* @return $this
* @throws \InvalidArgumentException
*/
public function errorMessage($message) : self
public function errorMessage(string $message) : self
{
return $this->renderBlock(' <fg=red>FAIL</> ', $message);
}
Expand Down Expand Up @@ -125,7 +135,7 @@ protected function renderBlock(string $block, string $message): self
$timer = $this->getTimer(true);
$alignment = $this->align(8, $this->align);

$this->write("[$block]$timer");
$this->write("{$timer}[$block]");
$this->write($alignment);
$this->writeln($message);

Expand Down Expand Up @@ -206,12 +216,14 @@ public function error($message) : self
* @throws \InvalidArgumentException
* @todo if type ==='' don't display []
*/
public function genericBlock($message, $background, $type, $length = 100) : self
public function genericBlock(string $message, string $background, string $type, int $length = 100) : self
{
$type = strtoupper($type);
$alignment = $this->align(0, $length);
$alignmentMessage = $this->align($message, $length - (mb_strlen($type) + 5));
$timer = $this->getTimer(true);

$timer ? $this->writeln($timer) : null;
$this->writeln("<bg=$background>$alignment</>");
$this->writeln("<fg=white;bg=$background> [$type] $message$alignmentMessage</>");
$this->writeln("<bg=$background>$alignment</>");
Expand Down

0 comments on commit 8c73819

Please sign in to comment.