Skip to content

Symfony Console Style tweaks #15964

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 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 16 additions & 8 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function title($message)
$this->autoPrependBlock();
$this->writeln(array(
sprintf('<comment>%s</>', $message),
sprintf('<comment>%s</>', str_repeat('=', strlen($message))),
sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
));
$this->newLine();
}
Expand All @@ -123,7 +123,7 @@ public function section($message)
$this->autoPrependBlock();
$this->writeln(array(
sprintf('<comment>%s</>', $message),
sprintf('<comment>%s</>', str_repeat('-', strlen($message))),
sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
));
$this->newLine();
}
Expand All @@ -149,14 +149,22 @@ public function text($message)
{
$this->autoPrependText();

if (!is_array($message)) {
$this->writeln(sprintf(' // %s', $message));

return;
$messages = is_array($message) ? array_values($message) : array($message);
foreach ($messages as $message) {
$this->writeln(sprintf(' %s', $message));
}
}

/**
* {@inheritdoc}
*/
public function comment($message)
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is not defined in the parent class. So inheritdoc makes no sense. Also I guess this method should be part of StyleInterface. But I don't really see the point of this interface either.

Copy link
Member

Choose a reason for hiding this comment

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

I'm very glad that I'm not the only one to wonder about why one insists on having interfaces for everything. Here again, I'm 👍 for removing this interface.

Copy link
Member

Choose a reason for hiding this comment

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

By the way, the interface is useless as we always create concrete instances instead of injecting them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can image a user-case: Having a centralized place where the style is created. And all commands would just work with StyleInterface. Thus one can easily replace the style evewhere. But that is not how commands currently work.

Copy link
Member

Choose a reason for hiding this comment

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

I am +1 for removing the interface as well. There was a reason for it that was discussed during the initial PR but I can't find it. Laravel is using this feature but they extend SymfonyStyle.

{
$this->autoPrependText();

foreach ($message as $element) {
$this->text($element);
$messages = is_array($message) ? array_values($message) : array($message);
foreach ($messages as $message) {
$this->writeln(sprintf(' // %s', $message));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@
'Lorem ipsum dolor sit amet',
'consectetur adipiscing elit',
));

$output->newLine();

$output->write('Lorem ipsum dolor sit amet');
$output->comment(array(
'Lorem ipsum dolor sit amet',
'consectetur adipiscing elit',
));
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Lorem ipsum dolor sit amet
* Lorem ipsum dolor sit amet
* consectetur adipiscing elit

Lorem ipsum dolor sit amet
Lorem ipsum dolor sit amet
consectetur adipiscing elit

Lorem ipsum dolor sit amet
// Lorem ipsum dolor sit amet
// consectetur adipiscing elit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Title
=====

// Duis aute irure dolor in reprehenderit in voluptate velit esse
Duis aute irure dolor in reprehenderit in voluptate velit esse