Skip to content

[RFC][Console] Added console style guide helpers (v2) #14057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0c653a0
added console style guide helpers
kbond Sep 25, 2014
b2bd430
added FormatterInterface and default formatters
kbond Sep 25, 2014
c71222f
added warning result bar
kbond Sep 25, 2014
e20283f
added OutputDecorator
kbond Sep 25, 2014
797a485
added comments
kbond Sep 25, 2014
c1c49c8
adjusted some formats
kbond Sep 25, 2014
bdb3704
added newline helper
kbond Sep 25, 2014
7110316
FormatterInterface::format returns string only
kbond Sep 25, 2014
4b30f14
fix cs
kbond Sep 25, 2014
a358431
fix string padding
kbond Sep 25, 2014
99ebf0e
refactored and simplified
kbond Sep 26, 2014
4d3e078
rename subtitle to section, fix docblocks
kbond Oct 2, 2014
72708d7
refactored
kbond Oct 2, 2014
a59fe02
added table helper
kbond Oct 2, 2014
bafefd6
added question helpers
kbond Oct 2, 2014
d767d28
added style guide table style
kbond Oct 2, 2014
273c187
added StandardQuestionHelper
kbond Oct 2, 2014
b0d2e6a
added table style to Table defaults
kbond Oct 2, 2014
9d82d6a
added `askHidden` helper
kbond Oct 2, 2014
525be2b
fix cs
kbond Oct 2, 2014
16ad7b9
refactored, removed FormatterInterface
kbond Oct 3, 2014
de14472
match current style guide
kbond Oct 3, 2014
d4d6f52
added vertical padding for blocks
kbond Oct 3, 2014
a33d8a7
various fixes
kbond Oct 3, 2014
18dbdb3
revert changes to FormatterHelper
kbond Mar 25, 2015
ae6d7a7
ensure formatter helper exists in QuestionHelper::writeError()
kbond Mar 26, 2015
5c774cc
simplify style tag
kbond Mar 26, 2015
c36189a
rename StyleInterface::ln() to StyleInterface:newLine()
kbond Mar 26, 2015
85cc04c
add StyleInterface::progress()
kbond Mar 26, 2015
e0efaa8
fix bug
kbond Mar 26, 2015
91941f8
add OutputStyle::progressStart, progressAdvance, progressFinish
kbond Mar 26, 2015
8143e77
remove StyleInterface::multipleChoice()
kbond Mar 26, 2015
f0cb90a
set custom progressbar characters only in non-windows environments
kbond Mar 27, 2015
bbdb37c
use DIRECTORY_SEPARATOR to detect Windows
kbond Mar 27, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added OutputDecorator
  • Loading branch information
kbond committed Mar 25, 2015
commit e20283f8dc2bc46d40bb76e234bfdbeefb8615f5
113 changes: 0 additions & 113 deletions src/Symfony/Component/Console/Helper/FormatterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@

use Symfony\Component\Console\Helper\Formatter\BlockFormatter;
use Symfony\Component\Console\Helper\Formatter\FormatterInterface;
use Symfony\Component\Console\Helper\Formatter\ListElementFormatter;
use Symfony\Component\Console\Helper\Formatter\SectionFormatter;
use Symfony\Component\Console\Helper\Formatter\SectionTitleFormatter;
use Symfony\Component\Console\Helper\Formatter\StyledBlockFormatter;
use Symfony\Component\Console\Helper\Formatter\TextFormatter;
use Symfony\Component\Console\Helper\Formatter\TitleFormatter;

/**
* The Formatter class provides helpers to format messages.
Expand Down Expand Up @@ -66,114 +61,6 @@ public function formatBlock($messages, $style, $large = false, $padLength = 0)
return $this->format(new BlockFormatter($messages, $style, $large, $padLength));
}

/**
* Formats a command title
*
* @param string $message
*
* @return array
*/
public function formatTitle($message)
{
return $this->format(new TitleFormatter($message));
}

/**
* Formats a section title
*
* @param string $message
*
* @return array
*/
public function formatSectionTitle($message)
{
return $this->format(new SectionTitleFormatter($message));
}

/**
* Formats a list element
*
* @param string|array $messages
*
* @return array
*/
public function formatListElement($messages)
{
return $this->format(new ListElementFormatter($messages));
}

/**
* Formats informational or debug text
*
* @param string|array $messages
*
* @return string
*/
public function formatText($messages)
{
return $this->format(new TextFormatter($messages));
}

/**
* Formats a success result bar
*
* @param string|array $messages
*
* @return array
*/
public function formatSuccessResultBar($messages)
{
return $this->format(new StyledBlockFormatter($messages, 'OK', 'fg=white;bg=green'));
}

/**
* Formats an error result bar
*
* @param string|array $messages
*
* @return array
*/
public function formatErrorResultBar($messages)
{
return $this->format(new StyledBlockFormatter($messages, 'ERROR', 'fg=white;bg=red'));
}

/**
* Formats an warning result bar
*
* @param string|array $messages
*
* @return array
*/
public function formatWarningResultBar($messages)
{
return $this->format(new StyledBlockFormatter($messages, 'WARNING', 'fg=black;bg=yellow'));
}

/**
* Formats a note admonition
*
* @param string|array $messages
*
* @return array
*/
public function formatNoteBlock($messages)
{
return $this->format(new StyledBlockFormatter($messages, 'NOTE', 'fg=white', '! '));
}

/**
* Formats a caution admonition
*
* @param string|array $messages
*
* @return array
*/
public function formatCautionBlock($messages)
{
return $this->format(new StyledBlockFormatter($messages, 'CAUTION', 'fg=white;bg=red', '! '));
}

/**
* {@inheritdoc}
*/
Expand Down
216 changes: 216 additions & 0 deletions src/Symfony/Component/Console/Output/OutputDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Helper\Formatter\BlockFormatter;
use Symfony\Component\Console\Helper\Formatter\FormatterInterface;
use Symfony\Component\Console\Helper\Formatter\ListElementFormatter;
use Symfony\Component\Console\Helper\Formatter\SectionFormatter;
use Symfony\Component\Console\Helper\Formatter\SectionTitleFormatter;
use Symfony\Component\Console\Helper\Formatter\StyledBlockFormatter;
use Symfony\Component\Console\Helper\Formatter\TextFormatter;
use Symfony\Component\Console\Helper\Formatter\TitleFormatter;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
class OutputDecorator implements OutputInterface
{
private $output;

/**
* @param OutputInterface $output
*/
public function __construct(OutputInterface $output)
{
$this->output = $output;
}

/**
* @param FormatterInterface $formatter
*/
public function format(FormatterInterface $formatter)
{
$this->writeln($formatter->format());
}

/**
* Formats a message within a section.
*
* @param string $section The section name
* @param string $message The message
* @param string $style The style to apply to the section
*/
public function section($section, $message, $style = 'info')
{
$this->format(new SectionFormatter($section, $message, $style));
}

/**
* Formats a message as a block of text.
*
* @param string|array $messages The message to write in the block
* @param string $style The style to apply to the whole block
* @param bool $large Whether to return a large block
* @param int $padLength Length to pad the messages
*/
public function block($messages, $style, $large = false, $padLength = 0)
{
$this->format(new BlockFormatter($messages, $style, $large, $padLength));
}

/**
* Formats a command title
*
* @param string $message
*/
public function title($message)
{
$this->format(new TitleFormatter($message));
}

/**
* Formats a section title
*
* @param string $message
*/
public function subtitle($message)
{
$this->format(new SectionTitleFormatter($message));
}

/**
* Formats a list element
*
* @param string|array $messages
*/
public function listElement($messages)
{
$this->format(new ListElementFormatter($messages));
}

/**
* Formats informational or debug text
*
* @param string|array $messages
*/
public function text($messages)
{
$this->format(new TextFormatter($messages));
}

/**
* Formats a success result bar
*
* @param string|array $messages
*/
public function success($messages)
{
$this->format(new StyledBlockFormatter($messages, 'OK', 'fg=white;bg=green'));
}

/**
* Formats an error result bar
*
* @param string|array $messages
*/
public function error($messages)
{
$this->format(new StyledBlockFormatter($messages, 'ERROR', 'fg=white;bg=red'));
}

/**
* Formats an warning result bar
*
* @param string|array $messages
*/
public function warning($messages)
{
$this->format(new StyledBlockFormatter($messages, 'WARNING', 'fg=black;bg=yellow'));
}

/**
* Formats a note admonition
*
* @param string|array $messages
*/
public function note($messages)
{
$this->format(new StyledBlockFormatter($messages, 'NOTE', 'fg=white', '! '));
}

/**
* Formats a caution admonition
*
* @param string|array $messages
*/
public function caution($messages)
{
$this->format(new StyledBlockFormatter($messages, 'CAUTION', 'fg=white;bg=red', '! '));
}

/**
* {@inheritdoc}
*/
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
{
$this->output->write($messages, $newline, $type);
}

/**
* {@inheritdoc}
*/
public function writeln($messages, $type = self::OUTPUT_NORMAL)
{
$this->output->writeln($messages, $type);
}

/**
* {@inheritdoc}
*/
public function setVerbosity($level)
{
$this->output->setVerbosity($level);
}

/**
* {@inheritdoc}
*/
public function getVerbosity()
{
return $this->output->getVerbosity();
}

/**
* {@inheritdoc}
*/
public function setDecorated($decorated)
{
$this->output->setDecorated($decorated);
}

/**
* {@inheritdoc}
*/
public function isDecorated()
{
return $this->output->isDecorated();
}

/**
* {@inheritdoc}
*/
public function setFormatter(OutputFormatterInterface $formatter)
{
$this->output->setFormatter($formatter);
}

/**
* {@inheritdoc}
*/
public function getFormatter()
{
return $this->output->getFormatter();
}
}