-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add title table #26933
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
[Console] Add title table #26933
Conversation
4aa5d6f
to
6d1bbfb
Compare
TABLE | ||
), | ||
array( | ||
'Boooooooooooooooooooooooooooooooooooooooooooooooooooooooooks', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about truncating instead of ignoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it's better. Done.
@@ -350,7 +361,7 @@ public function render() | |||
* | |||
* Example: <code>+-----+-----------+-------+</code> | |||
*/ | |||
private function renderRowSeparator(int $type = self::SEPARATOR_MID) | |||
private function renderRowSeparator(int $type = self::SEPARATOR_MID, $title = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string $title = null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -290,6 +292,13 @@ public function setRow($column, array $row) | |||
return $this; | |||
} | |||
|
|||
public function setTitle($title): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?string $title
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
6d1bbfb
to
706bab2
Compare
'Boooooooooooooooooooooooooooooooooooooooooooooooooooooooooks', | ||
'default', | ||
<<<'TABLE' | ||
+ Booooooooooooooooooooooooooooooooooooooooooooooooooooooo... + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we leave at least 1 separator character for long titles in the head? Instead of this:
+ Booooooooooooooooooooooooooooooooooooooooooooooooooooooo... +
| ISBN | Title | Author |
+---------------+--------------------------+------------------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
| ...
This:
+- Booooooooooooooooooooooooooooooooooooooooooooooooooooo... -+
| ISBN | Title | Author |
+---------------+--------------------------+------------------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
| ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. That looks much better!
@@ -72,6 +72,18 @@ public static function substr($string, $from, $length = null) | |||
return mb_substr($string, $from, $length, $encoding); | |||
} | |||
|
|||
/** | |||
* Returns the text within a portion of a string, using mb_substr if it is available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove ... using mb_substr if it is available
from the description because it's an internal detail and in the PHPdoc we usually only explain what we do but not how we do that.
Also, the description is a bit confusing Returns the text within a portion of a string ...
because the function name means Replace a part of the given string...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had put the mb_substr
detail to be consistent with the others methods of this helper, but effectively, that isn't really useful, so it's deleted now.
About the description, I reworded to Replaces text within a portion of a string
(the same description than in the PHP doc)
@@ -378,6 +389,17 @@ private function renderRowSeparator(int $type = self::SEPARATOR_MID) | |||
$markup .= $column === $count - 1 ? $rightChar : $midChar; | |||
} | |||
|
|||
if (null !== $title) { | |||
$lenT = Helper::strlenWithoutDecoration($formatter = $this->output->getFormatter(), $formattedTitle = sprintf($format = $this->style->getTitleFormat(), $title)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use better variable names here to ease future maintenance. For example:
$lenT -> $titleTextLength
$lenM -> $titleMarkupLength
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed :)
30a72f8
to
47183ed
Compare
Would it make sense to allow the title to be at the bottom as well? |
@fabpot What do you mean by "at the bottom"? The second line of the header or the very last line of the table? |
I was thinking about the last line of the table. |
IMO, shown the title only in the first line is enough. |
Not sure I understand the "enough" part. I was thinking about letting the user choose between displaying the title at the top or at the bottom (depending on what you want to achieve, doing one or the other might make more sense). |
What about |
Also sometimes the table is too big, showing the title in both places (top/bottom) would be nice, avoids scrolling. |
47183ed
to
57da8ae
Compare
57da8ae
to
8a6396f
Compare
return $this; | ||
} | ||
|
||
public function setfooterTitle(?string $title): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/footer/Footer/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return $this; | ||
} | ||
|
||
public function setfooterTitle(?string $title): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method should be renamed to setFooterTitle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
8a6396f
to
63f973f
Compare
/** | ||
* Replaces text within a portion of a string. | ||
*/ | ||
public static function substr_replace(string $string, string $replacement, int $start, int $length = null): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this actually complies with CS ... should we prefer substrReplace()
(given strlenWithoutDecoration
also)
but i understand the reasoning.. i don't mind really :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, someone like @nicolas-grekas could help us here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the logic is used once: let's inline it instead of creating a new public method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined!
return substr_replace($string, $replacement, $start, $length); | ||
} | ||
|
||
return mb_substr($string, 0, $start).$replacement.mb_substr($string, $start + $length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from http://php.net/manual/en/function.substr-replace.php
i think we should default $length = strlen($string);
here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks working as expected https://3v4l.org/C5Nhs, do I miss something ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like PHP treats null
as int(0)
🤔
63f973f
to
957568f
Compare
@@ -17,6 +17,7 @@ | |||
* Helper is the base class for all helper classes. | |||
* | |||
* @author Fabien Potencier <[email protected]> | |||
* @author Dany Maillard <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I just removed it.
957568f
to
6bf9eeb
Compare
Thank you @maidmaid. |
This PR was merged into the 4.2-dev branch. Discussion ---------- [Console] Add title table | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | / | License | MIT | Doc PR | / Why not just add a title to console tables? Inspired by the famous file manager [Midnight Commander](https://en.wikipedia.org/wiki/Midnight_Commander).  Commits ------- 6bf9eeb Add title table
I've created symfony/symfony-docs#10294 to not forget about adding the docs for this feature. @maidmaid it'd be great if you could help us with the docs for this feature. Thanks! |
Why not just add a title to console tables? Inspired by the famous file manager Midnight Commander.