@@ -14,7 +14,7 @@ |
||
| 14 | 14 | public static function wordwrap(string $str, int $width, string $break = "\n") : string |
| 15 | 15 | { |
| 16 | 16 | $length = 0; |
| 17 | - return implode(' ', array_map(function ($word) use (&$length, $width, $break) { |
|
| 17 | + return implode(' ', array_map(function($word) use (&$length, $width, $break) { |
|
| 18 | 18 | $length += (mb_strlen($word) + 1); |
| 19 | 19 | |
| 20 | 20 | if ($length > $width) { |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | ) |
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | - return array_map(function ($row, $key) use ($style, $length) { |
|
| 48 | + return array_map(function($row, $key) use ($style, $length) { |
|
| 49 | 49 | $text = $this->disabled ? $style->getDisabledItemText($row) : $row; |
| 50 | 50 | |
| 51 | 51 | if ($key === 0) { |
@@ -267,7 +267,7 @@ |
||
| 267 | 267 | |
| 268 | 268 | public function setWidth(int $width) : self |
| 269 | 269 | { |
| 270 | - $availableWidth = $this->terminal->getWidth() - ($this->margin * 2) - ($this->padding * 2); |
|
| 270 | + $availableWidth = $this->terminal->getWidth() - ($this->margin*2) - ($this->padding*2); |
|
| 271 | 271 | |
| 272 | 272 | if ($width >= $availableWidth) { |
| 273 | 273 | $width = $availableWidth; |
@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace PhpSchool\CliMenu; |
| 4 | 4 | |
| 5 | -use PhpSchool\CliMenu\Exception\InvalidInstantiationException; |
|
| 6 | 5 | use PhpSchool\CliMenu\Terminal\TerminalFactory; |
| 7 | 6 | use PhpSchool\Terminal\Terminal; |
| 8 | 7 | |
@@ -79,11 +79,11 @@ |
||
| 79 | 79 | |
| 80 | 80 | public function ask() : InputResult |
| 81 | 81 | { |
| 82 | - $this->inputIO->registerControlCallback(InputCharacter::UP, function (string $input) { |
|
| 82 | + $this->inputIO->registerControlCallback(InputCharacter::UP, function(string $input) { |
|
| 83 | 83 | return $this->validate($input) ? $input + 1 : $input; |
| 84 | 84 | }); |
| 85 | 85 | |
| 86 | - $this->inputIO->registerControlCallback(InputCharacter::DOWN, function (string $input) { |
|
| 86 | + $this->inputIO->registerControlCallback(InputCharacter::DOWN, function(string $input) { |
|
| 87 | 87 | return $this->validate($input) ? $input - 1 : $input; |
| 88 | 88 | }); |
| 89 | 89 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | { |
| 97 | 97 | return max( |
| 98 | 98 | array_map( |
| 99 | - function (string $line) { |
|
| 99 | + function(string $line) { |
|
| 100 | 100 | return mb_strlen($line); |
| 101 | 101 | }, |
| 102 | 102 | $lines |
@@ -108,14 +108,14 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $lines = 5; //1. empty 2. prompt text 3. empty 4. input 5. empty |
| 110 | 110 | |
| 111 | - return ceil($this->parentMenu->getCurrentFrame()->count() / 2) - ceil($lines /2) + 1; |
|
| 111 | + return ceil($this->parentMenu->getCurrentFrame()->count()/2) - ceil($lines/2) + 1; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | private function calculateYPositionWithError() : int |
| 115 | 115 | { |
| 116 | 116 | $lines = 7; //1. empty 2. prompt text 3. empty 4. input 5. empty 6. error 7. empty |
| 117 | 117 | |
| 118 | - return ceil($this->parentMenu->getCurrentFrame()->count() / 2) - ceil($lines /2) + 1; |
|
| 118 | + return ceil($this->parentMenu->getCurrentFrame()->count()/2) - ceil($lines/2) + 1; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | private function calculateXPosition(Input $input, string $userInput) : int |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | ); |
| 130 | 130 | |
| 131 | 131 | $parentStyle = $this->parentMenu->getStyle(); |
| 132 | - $halfWidth = ($width + ($input->getStyle()->getPadding() * 2)) / 2; |
|
| 133 | - $parentHalfWidth = ceil($parentStyle->getWidth() / 2); |
|
| 132 | + $halfWidth = ($width + ($input->getStyle()->getPadding()*2))/2; |
|
| 133 | + $parentHalfWidth = ceil($parentStyle->getWidth()/2); |
|
| 134 | 134 | |
| 135 | 135 | return $parentHalfWidth - $halfWidth; |
| 136 | 136 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | 164 | $textLength = mb_strlen(StringUtil::stripAnsiEscapeSequence($text)); |
| 165 | - $leftFill = ($width / 2) - ($textLength / 2); |
|
| 165 | + $leftFill = ($width/2) - ($textLength/2); |
|
| 166 | 166 | $rightFill = ceil($width - $leftFill - $textLength); |
| 167 | 167 | |
| 168 | 168 | $this->drawLine( |
@@ -3,12 +3,12 @@ |
||
| 3 | 3 | use PhpSchool\CliMenu\CliMenu; |
| 4 | 4 | use PhpSchool\CliMenu\CliMenuBuilder; |
| 5 | 5 | |
| 6 | -require_once(__DIR__ . '/../vendor/autoload.php'); |
|
| 6 | +require_once(__DIR__.'/../vendor/autoload.php'); |
|
| 7 | 7 | |
| 8 | -$itemCallable = function (CliMenu $menu) { |
|
| 8 | +$itemCallable = function(CliMenu $menu) { |
|
| 9 | 9 | $result = $menu->askPassword() |
| 10 | 10 | ->setPlaceholderText('') |
| 11 | - ->setValidator(function ($password) { |
|
| 11 | + ->setValidator(function($password) { |
|
| 12 | 12 | if ($password === 'password') { |
| 13 | 13 | $this->setValidationFailedText('Password is too weak'); |
| 14 | 14 | return false; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function addSubMenu(string $id, CliMenuBuilder $subMenuBuilder = null) : CliMenuBuilder |
| 154 | 154 | { |
| 155 | - $this->menuItems[] = $id; |
|
| 155 | + $this->menuItems[] = $id; |
|
| 156 | 156 | |
| 157 | 157 | if (null === $subMenuBuilder) { |
| 158 | 158 | $this->subMenuBuilders[$id] = new static($this); |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | |
| 295 | 295 | private function itemsHaveExtra(array $items) : bool |
| 296 | 296 | { |
| 297 | - return !empty(array_filter($items, function (MenuItemInterface $item) { |
|
| 297 | + return !empty(array_filter($items, function(MenuItemInterface $item) { |
|
| 298 | 298 | return $item->showsItemExtra(); |
| 299 | 299 | })); |
| 300 | 300 | } |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | private function buildSubMenus(array $items) : array |
| 361 | 361 | { |
| 362 | - return array_map(function ($item) { |
|
| 362 | + return array_map(function($item) { |
|
| 363 | 363 | if (!is_string($item)) { |
| 364 | 364 | return $item; |
| 365 | 365 | } |
@@ -3,9 +3,9 @@ |
||
| 3 | 3 | use PhpSchool\CliMenu\CliMenu; |
| 4 | 4 | use PhpSchool\CliMenu\CliMenuBuilder; |
| 5 | 5 | |
| 6 | -require_once(__DIR__ . '/../vendor/autoload.php'); |
|
| 6 | +require_once(__DIR__.'/../vendor/autoload.php'); |
|
| 7 | 7 | |
| 8 | -$exit = function (CliMenu $menu) { |
|
| 8 | +$exit = function(CliMenu $menu) { |
|
| 9 | 9 | $menu->close(); |
| 10 | 10 | }; |
| 11 | 11 | |
@@ -3,9 +3,9 @@ discard block |
||
| 3 | 3 | use PhpSchool\CliMenu\CliMenu; |
| 4 | 4 | use PhpSchool\CliMenu\CliMenuBuilder; |
| 5 | 5 | |
| 6 | -require_once(__DIR__ . '/../vendor/autoload.php'); |
|
| 6 | +require_once(__DIR__.'/../vendor/autoload.php'); |
|
| 7 | 7 | |
| 8 | -$itemCallable = function (CliMenu $menu) { |
|
| 8 | +$itemCallable = function(CliMenu $menu) { |
|
| 9 | 9 | echo $menu->getSelectedItem()->getText(); |
| 10 | 10 | }; |
| 11 | 11 | |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | ->addLineBreak('-') |
| 17 | 17 | ->addSubMenu('Options') |
| 18 | 18 | ->setTitle('CLI Menu > Options') |
| 19 | - ->addItem('First option', function (CliMenu $menu) { |
|
| 19 | + ->addItem('First option', function(CliMenu $menu) { |
|
| 20 | 20 | echo sprintf('Executing option: %s', $menu->getSelectedItem()->getText()); |
| 21 | 21 | }) |
| 22 | 22 | ->addSubMenu('Secret Options') |
| 23 | 23 | ->setTitle('CLI Menu > Options > Secret Options') |
| 24 | - ->addItem('First secret option', function (CliMenu $menu) { |
|
| 24 | + ->addItem('First secret option', function(CliMenu $menu) { |
|
| 25 | 25 | echo sprintf('Executing secret option: %s', $menu->getSelectedItem()->getText()); |
| 26 | 26 | }) |
| 27 | 27 | ->addLineBreak('-') |