@@ -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 | |
@@ -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('-') |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | : $this->selectedItem++; |
| 269 | 269 | |
| 270 | 270 | if (!array_key_exists($this->selectedItem, $this->items)) { |
| 271 | - $this->selectedItem = $direction === 'UP' |
|
| 271 | + $this->selectedItem = $direction === 'UP' |
|
| 272 | 272 | ? end($itemKeys) |
| 273 | 273 | : reset($itemKeys); |
| 274 | 274 | } elseif ($this->getSelectedItem()->canSelect()) { |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $frame->addRows($this->drawMenuItem(new LineBreakItem($this->style->getTitleSeparator()))); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - array_map(function ($item, $index) use ($frame) { |
|
| 329 | + array_map(function($item, $index) use ($frame) { |
|
| 330 | 330 | $frame->addRows($this->drawMenuItem($item, $index === $this->selectedItem)); |
| 331 | 331 | }, $this->items, array_keys($this->items)); |
| 332 | 332 | |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | ? $this->style->getInvertedColoursSetCode() |
| 360 | 360 | : ''; |
| 361 | 361 | |
| 362 | - return array_map(function ($row) use ($setColour, $invertedColour, $resetColour) { |
|
| 362 | + return array_map(function($row) use ($setColour, $invertedColour, $resetColour) { |
|
| 363 | 363 | return sprintf( |
| 364 | 364 | "%s%s%s%s%s%s%s%s\n", |
| 365 | 365 | str_repeat(' ', $this->style->getMargin()), |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | $this->emptyRow(); |
| 37 | 37 | |
| 38 | 38 | $confirmText = sprintf(' < %s > ', $confirmText); |
| 39 | - $leftFill = ($promptWidth / 2) - (mb_strlen($confirmText) / 2); |
|
| 39 | + $leftFill = ($promptWidth/2) - (mb_strlen($confirmText)/2); |
|
| 40 | 40 | |
| 41 | 41 | $this->write(sprintf( |
| 42 | 42 | "%s%s%s%s%s%s%s\n", |
@@ -69,12 +69,12 @@ |
||
| 69 | 69 | { |
| 70 | 70 | //y |
| 71 | 71 | $textLines = count(explode("\n", $this->text)) + 2; |
| 72 | - $this->y = ceil($this->parentMenu->getCurrentFrame()->count() / 2) - ceil($textLines / 2) + 1; |
|
| 72 | + $this->y = ceil($this->parentMenu->getCurrentFrame()->count()/2) - ceil($textLines/2) + 1; |
|
| 73 | 73 | |
| 74 | 74 | //x |
| 75 | 75 | $parentStyle = $this->parentMenu->getStyle(); |
| 76 | - $dialogueHalfLength = (mb_strlen($this->text) + ($this->style->getPadding() * 2)) / 2; |
|
| 77 | - $widthHalfLength = ceil($parentStyle->getWidth() / 2 + $parentStyle->getMargin()); |
|
| 76 | + $dialogueHalfLength = (mb_strlen($this->text) + ($this->style->getPadding()*2))/2; |
|
| 77 | + $widthHalfLength = ceil($parentStyle->getWidth()/2 + $parentStyle->getMargin()); |
|
| 78 | 78 | $this->x = $widthHalfLength - $dialogueHalfLength; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | return max( |
| 100 | 100 | array_map( |
| 101 | - function (string $line) { |
|
| 101 | + function(string $line) { |
|
| 102 | 102 | return mb_strlen($line); |
| 103 | 103 | }, |
| 104 | 104 | $lines |
@@ -110,14 +110,14 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $lines = 5; //1. empty 2. prompt text 3. empty 4. input 5. empty |
| 112 | 112 | |
| 113 | - return ceil($this->parentMenu->getCurrentFrame()->count() / 2) - ceil($lines /2) + 1; |
|
| 113 | + return ceil($this->parentMenu->getCurrentFrame()->count()/2) - ceil($lines/2) + 1; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | private function calculateYPositionWithError() : int |
| 117 | 117 | { |
| 118 | 118 | $lines = 7; //1. empty 2. prompt text 3. empty 4. input 5. empty 6. error 7. empty |
| 119 | 119 | |
| 120 | - return ceil($this->parentMenu->getCurrentFrame()->count() / 2) - ceil($lines /2) + 1; |
|
| 120 | + return ceil($this->parentMenu->getCurrentFrame()->count()/2) - ceil($lines/2) + 1; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | private function calculateXPosition(Input $input, string $userInput) : int |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | $parentStyle = $this->parentMenu->getStyle(); |
| 134 | - $halfWidth = ($width + ($input->getStyle()->getPadding() * 2)) / 2; |
|
| 135 | - $parentHalfWidth = ceil($parentStyle->getWidth() / 2 + $parentStyle->getMargin()); |
|
| 134 | + $halfWidth = ($width + ($input->getStyle()->getPadding()*2))/2; |
|
| 135 | + $parentHalfWidth = ceil($parentStyle->getWidth()/2 + $parentStyle->getMargin()); |
|
| 136 | 136 | |
| 137 | 137 | return $parentHalfWidth - $halfWidth; |
| 138 | 138 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | 166 | $textLength = mb_strlen(StringUtil::stripAnsiEscapeSequence($text)); |
| 167 | - $leftFill = ($width / 2) - ($textLength / 2); |
|
| 167 | + $leftFill = ($width/2) - ($textLength/2); |
|
| 168 | 168 | $rightFill = ceil($width - $leftFill - $textLength); |
| 169 | 169 | |
| 170 | 170 | $this->drawLine( |