@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | /** |
209 | 209 | * Move the selection in a given direction, up / down |
210 | 210 | * |
211 | - * @param $direction |
|
211 | + * @param string $direction |
|
212 | 212 | */ |
213 | 213 | protected function moveSelection($direction) |
214 | 214 | { |
@@ -462,6 +462,9 @@ discard block |
||
462 | 462 | return new Password(new InputIO($this, $style, $this->terminal)); |
463 | 463 | } |
464 | 464 | |
465 | + /** |
|
466 | + * @param string $text |
|
467 | + */ |
|
465 | 468 | private function guardSingleLine($text) |
466 | 469 | { |
467 | 470 | if (strpos($text, "\n") !== false) { |
@@ -2,8 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace PhpSchool\CliMenu; |
4 | 4 | |
5 | -use PhpSchool\CliMenu\Dialogue\NumberInput; |
|
6 | -use PhpSchool\CliMenu\Exception\InvalidInstantiationException; |
|
7 | 5 | use PhpSchool\CliMenu\Exception\InvalidTerminalException; |
8 | 6 | use PhpSchool\CliMenu\Exception\MenuNotOpenException; |
9 | 7 | use PhpSchool\CliMenu\Input\InputIO; |
@@ -3,20 +3,20 @@ |
||
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 | |
12 | 12 | $menu = (new CliMenuBuilder) |
13 | 13 | ->setTitle('Basic CLI Menu') |
14 | 14 | ->addItem('First Item', $itemCallable) |
15 | - ->addItem('Second Item', function (CliMenu $menu) { |
|
15 | + ->addItem('Second Item', function(CliMenu $menu) { |
|
16 | 16 | $menu->getStyle()->setBg('red'); |
17 | 17 | $menu->redraw(); |
18 | 18 | }) |
19 | - ->addItem('Third Item', function (CliMenu $menu) { |
|
19 | + ->addItem('Third Item', function(CliMenu $menu) { |
|
20 | 20 | $menu->getStyle()->setBg('default'); |
21 | 21 | $menu->redraw(); |
22 | 22 | }) |
@@ -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 | -$itemCallable = function (CliMenu $menu) { |
|
8 | +$itemCallable = function(CliMenu $menu) { |
|
9 | 9 | $result = $menu->askPassword() |
10 | 10 | ->setPlaceholderText('') |
11 | 11 | ->ask(); |
@@ -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 | -$itemCallable = function (CliMenu $menu) { |
|
8 | +$itemCallable = function(CliMenu $menu) { |
|
9 | 9 | $result = $menu->askText() |
10 | 10 | ->setPlaceholderText('Enter something here') |
11 | 11 | ->ask(); |
@@ -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 | -$itemCallable = function (CliMenu $menu) { |
|
8 | +$itemCallable = function(CliMenu $menu) { |
|
9 | 9 | $result = $menu->askNumber() |
10 | 10 | ->setPlaceholderText(10) |
11 | 11 | ->ask(); |
@@ -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 | -$itemCallable = function (CliMenu $menu) { |
|
8 | +$itemCallable = function(CliMenu $menu) { |
|
9 | 9 | $username = $menu->askText() |
10 | 10 | ->setPromptText('Enter username') |
11 | 11 | ->setPlaceholderText('alice') |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | { |
106 | 106 | return max( |
107 | 107 | array_map( |
108 | - function (string $line) { |
|
108 | + function(string $line) { |
|
109 | 109 | return mb_strlen($line); |
110 | 110 | }, |
111 | 111 | $lines |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | { |
118 | 118 | $lines = 5; //1. empty 2. prompt text 3. empty 4. input 5. 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 calculateYPositionWithError() : int |
124 | 124 | { |
125 | 125 | $lines = 7; //1. empty 2. prompt text 3. empty 4. input 5. empty 6. error 7. empty |
126 | 126 | |
127 | - return ceil($this->parentMenu->getCurrentFrame()->count() / 2) - ceil($lines /2) + 1; |
|
127 | + return ceil($this->parentMenu->getCurrentFrame()->count()/2) - ceil($lines/2) + 1; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | private function calculateXPosition(Input $input, string $userInput) : int |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | ); |
139 | 139 | |
140 | 140 | $parentStyle = $this->parentMenu->getStyle(); |
141 | - $halfWidth = ($width + ($this->style->getPadding() * 2)) / 2; |
|
142 | - $parentHalfWidth = ceil($parentStyle->getWidth() / 2); |
|
141 | + $halfWidth = ($width + ($this->style->getPadding()*2))/2; |
|
142 | + $parentHalfWidth = ceil($parentStyle->getWidth()/2); |
|
143 | 143 | |
144 | 144 | return $parentHalfWidth - $halfWidth; |
145 | 145 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ); |
170 | 170 | |
171 | 171 | $textLength = mb_strlen(StringUtil::stripAnsiEscapeSequence($text)); |
172 | - $leftFill = ($width / 2) - ($textLength / 2); |
|
172 | + $leftFill = ($width/2) - ($textLength/2); |
|
173 | 173 | $rightFill = ceil($width - $leftFill - $textLength); |
174 | 174 | |
175 | 175 | $this->drawLine( |
@@ -73,11 +73,11 @@ |
||
73 | 73 | $this->inputIO->registerInputMap("\033[A", 'up'); |
74 | 74 | $this->inputIO->registerInputMap("\033[B", 'down'); |
75 | 75 | |
76 | - $this->inputIO->registerControlCallback('up', function (InputIO $inputIO, string $input) { |
|
76 | + $this->inputIO->registerControlCallback('up', function(InputIO $inputIO, string $input) { |
|
77 | 77 | return $this->validate($input) ? $input + 1 : $input; |
78 | 78 | }); |
79 | 79 | |
80 | - $this->inputIO->registerControlCallback('down', function (InputIO $inputIO, string $input) { |
|
80 | + $this->inputIO->registerControlCallback('down', function(InputIO $inputIO, string $input) { |
|
81 | 81 | return $this->validate($input) ? $input - 1 : $input; |
82 | 82 | }); |
83 | 83 |