Skip to content
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

Merged
merged 16 commits into from
Apr 30, 2018
Merged

Inputs #81

merged 16 commits into from
Apr 30, 2018

Conversation

AydinHassan
Copy link
Member

  • Migrates to php-school/terminal - currently dev-master we will change that before merging or next release anyway
  • Adds inputs + tests

This PR is quite long, but there should be some stuff that can be ignored for review, will annotate.

@AydinHassan AydinHassan mentioned this pull request Apr 23, 2018
composer.json Outdated
@@ -21,6 +21,7 @@
"require": {
"php" : ">=7.1",
"beberlei/assert": "^2.4",
"php-school/terminal": "dev-master",
Copy link
Member Author

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)');
Copy link
Member Author

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-io
Copy link

codecov-io commented Apr 23, 2018

Codecov Report

Merging #81 into master will increase coverage by 7.36%.
The diff coverage is 97.99%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
src/Input/Text.php 100% <100%> (ø) 11 <11> (?)
src/CliMenuBuilder.php 98.55% <100%> (ø) 43 <1> (ø) ⬇️
src/Input/Password.php 100% <100%> (ø) 14 <14> (?)
src/Input/Number.php 100% <100%> (ø) 14 <14> (?)
src/Dialogue/Dialogue.php 90% <100%> (ø) 8 <1> (ø) ⬇️
src/Terminal/TerminalFactory.php 100% <100%> (ø) 1 <1> (ø) ⬇️
src/Input/InputResult.php 100% <100%> (ø) 2 <2> (?)
src/Dialogue/Flash.php 100% <100%> (ø) 1 <0> (ø) ⬇️
src/Dialogue/Confirm.php 100% <100%> (ø) 4 <0> (+2) ⬆️
src/MenuStyle.php 94.54% <100%> (ø) 35 <2> (ø) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6270594...32b500a. Read the comment docs.

@@ -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",
Copy link
Member Author

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);
Copy link
Member Author

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) {
Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member

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 @@


 
 PHP School FTW 
Copy link
Member Author

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


public function validate(string $input) : bool
{
return (bool) preg_match('/^\d+$/', $input);
Copy link
Member

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?

Copy link
Member Author

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.

{
if ($this->validator) {
$validator = $this->validator;
return $validator($input);
Copy link
Member

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 ?

Copy link
Member Author

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.

Copy link
Member

@mikeymike mikeymike left a 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

screen shot 2018-04-28 at 21 49 20

I did that by doing alt+delete then inputting as normal

screen shot 2018-04-28 at 21 51 33

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 ?

@AydinHassan
Copy link
Member Author

@mikeymike damn you for breaking! - will take a look

@AydinHassan
Copy link
Member Author

@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

@mikeymike
Copy link
Member

❤️ merging

@mikeymike mikeymike merged commit 4c883fb into master Apr 30, 2018
@mikeymike mikeymike deleted the inputs-new branch April 30, 2018 11:24
@AydinHassan AydinHassan added this to the 3.0 milestone May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants