Skip to content

Commit dcd1df7

Browse files
authored
Merge pull request #164 from php-school/auto-width-docs
Auto width docs
2 parents bc045d4 + e955747 commit dcd1df7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,33 @@ $menu = (new CliMenuBuilder)
296296
->build();
297297
```
298298

299+
If you want to use the full width of the terminal, you can grab the terminal object and ask/set it from there like so:
300+
301+
```php
302+
<?php
303+
304+
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
305+
306+
$menu = ($builder = new CliMenuBuilder)
307+
->setWidth($builder->getTerminal()->getWidth())
308+
->build();
309+
```
310+
311+
If you want to use the full width of the terminal and apply a margin you will need to perform a little calculation yourself
312+
since we use a box model like the `box-sizing: border-box;` in CSS. The example below will use the full width of the terminal plus a margin of 2 on the
313+
left and right sides:
314+
315+
```php
316+
<?php
317+
318+
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
319+
320+
$menu = ($builder = new CliMenuBuilder)
321+
->setWidth($builder->getTerminal()->getWidth() - 2 * 2)
322+
->setMargin(2)
323+
->build();
324+
```
325+
299326
#### Padding
300327

301328
The padding can be set for all sides with one value or can be set individually for top/bottom and left/right.

0 commit comments

Comments
 (0)