-
Notifications
You must be signed in to change notification settings - Fork 107
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
Inputs #81
Inputs #81
Conversation
composer.json
Outdated
@@ -21,6 +21,7 @@ | |||
"require": { | |||
"php" : ">=7.1", | |||
"beberlei/assert": "^2.4", | |||
"php-school/terminal": "dev-master", |
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.
Needs updating when we tag first release.
sprintf('Terminal "%s" is not a valid TTY', $this->terminal->getDetails()) | ||
); | ||
if (!$this->terminal->isInteractive()) { | ||
throw new InvalidTerminalException('Terminal is not interactive (TTY)'); |
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.
This is what I mentioned in the php-school/terminal
PR. If it's not a valid TTY - then there is no name.
Codecov Report
@@ Coverage Diff @@
## master #81 +/- ##
============================================
+ Coverage 89.13% 96.49% +7.36%
- Complexity 246 288 +42
============================================
Files 18 22 +4
Lines 690 885 +195
============================================
+ Hits 615 854 +239
+ Misses 75 31 -44
Continue to review full report at Codecov.
|
@@ -277,7 +297,7 @@ protected function drawMenuItem(MenuItemInterface $item, bool $selected = false) | |||
|
|||
return array_map(function ($row) use ($setColour, $unsetColour) { | |||
return sprintf( | |||
"%s%s%s%s%s%s%s\n\r", |
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.
dropped this \r
because we don't support windows anymore and phpstorm keep changing the line endings when I was editing the test files which was mega annoying.
@@ -33,35 +36,21 @@ public function display(string $confirmText = 'OK') : void | |||
$this->emptyRow(); | |||
|
|||
$confirmText = sprintf(' < %s > ', $confirmText); | |||
$leftFill = ($promptWidth / 2) - (mb_strlen($confirmText) / 2); |
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.
All these changes before the while loop are just refactorings, no logic change
|
||
public function ask() : InputResult | ||
{ | ||
$this->inputIO->registerControlCallback(InputCharacter::UP, function (string $input) { |
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.
If the user presses up while they are giving a number (and the current input is actually a number) then we shift it up 1
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 dont validate until they hit enter and therefore if they enter a string we can't really increment it
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.
this functionality though 🔥
@@ -1,23 +1,23 @@ | |||
|
|||
|
|||
[44;37m [49;39m | |||
[44;37m PHP School FTW [49;39m |
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.
all these text file changes are just removing \r
src/Input/Number.php
Outdated
|
||
public function validate(string $input) : bool | ||
{ | ||
return (bool) preg_match('/^\d+$/', $input); |
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.
this fails negative numbers, not sure but I'd think we'd want to accept that right?
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.
Yeah defo - will fix up.
src/Input/Password.php
Outdated
{ | ||
if ($this->validator) { | ||
$validator = $this->validator; | ||
return $validator($input); |
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.
1 thing I noticed here was that a developer could potentially have quite a complex validator added to an input with 1 or more "rules"... however there's no way to feedback from that validator the error that occurred, in this case they'd need to create a new input type
What do you think, worth refactoring a little for that ?
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.
Yeah I thought about this but was being lazy. Probably allow to throw an exception and use the exception message, bit like how symfony does.
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.
Overall man I love this, I did however still manage to break it to produce this
I did that by doing alt+delete
then inputting as normal
This one I did by checking if maybe alt+delete
was somewhat equal to the standard ctrl+u
which deletes lines etc as I know I have alt+delete
in my terminal mapped to delete words
I believe ctrl+p
and other random shortcuts lead to similar behaviour ... wonder if there's a list of standard bindings we'd need to cater for ?
@mikeymike damn you for breaking! - will take a look |
@mikeymike should all be addressed now - we just ignore all controls now, and allow handling specific ones. For ctrl +p, ctrl +u we just plain ignore. We can add support for them in the future if we wanted as I mentioned in php-school/terminal#5 |
❤️ merging |
php-school/terminal
- currently dev-master we will change that before merging or next release anywayThis PR is quite long, but there should be some stuff that can be ignored for review, will annotate.