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
add StyleInterface::progress()
  • Loading branch information
kbond committed Mar 26, 2015
commit 85cc04c7f90d8e79c6d166899b51ee72c67a8fdc
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Style/OutputStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Console\Style;

use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -39,6 +40,14 @@ public function newLine($count = 1)
$this->output->write(str_repeat(PHP_EOL, $count));
}

/**
* {@inheritdoc}
*/
public function progress($max = 0)
{
return new ProgressBar($this->output, $max);
}

/**
* {@inheritdoc}
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Style/StyleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Console\Style;

use Symfony\Component\Console\Helper\ProgressBar;

/**
* Output style helpers
*
Expand Down Expand Up @@ -148,4 +150,11 @@ public function multipleChoice($question, array $choices, array $default = array
* @param int $count The number of newlines
*/
public function newLine($count = 1);

/**
* @param int $max Maximum steps (0 if unknown)
*
* @return ProgressBar
*/
public function progress($max = 0);
}
13 changes: 13 additions & 0 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ public function multipleChoice($question, array $choices, array $default = array
return $this->askQuestion($question);
}

/**
* {@inheritdoc}
*/
public function progress($max = 0)
{
$progress = parent::progress($max);
$progress->setEmptyBarCharacter('░'); // light shade character \u2591
$progress->setProgressCharacter('');
$progress->setBarCharacter('▓'); // dark shade character \u2593
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these special characters should only be used when supported. At the moment, Windows doesn't support it. We should do something like:

if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
    $progressBar->setEmptyBarCharacter(''); // light shade character \u2591
    $progressBar->setProgressCharacter('');
    $progressBar->setBarCharacter(''); // dark shade character \u2593
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and it depends on the font http://www.fileformat.info/info/unicode/char/2593/fontsupport.htm and even looks different in different terminal emulators with the same font

gnome-terminal
screenshot from 2015-03-27 12 20 24

terminator
screenshot from 2015-03-27 12 21 46

So use something basic like # (which e.g. curl and apt uses) would be less complicated and more consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add @wouterj's recommended code for now but we can always finalize the style later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1ed you are right, but we don't try to make it look exactly the same for the millions of different combinations that exist out there. Let's try this style and get community feedback. If most people see it correctly and a tiny fraction of users have problems, we'll try to provide an alternative solution for that minority. If most people see it wrongly, we'll change the styles. Thanks.


return $progress;
}

/**
* @param Question $question
*
Expand Down