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

Add border styling #100

Merged
merged 36 commits into from
May 7, 2018
Merged

Add border styling #100

merged 36 commits into from
May 7, 2018

Conversation

Lynesth
Copy link
Collaborator

@Lynesth Lynesth commented May 4, 2018

No description provided.

src/CliMenu.php Outdated
@@ -319,6 +319,27 @@ protected function draw() : void
$frame = new Frame;

$frame->newLine(2);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the $borderRow could be stored in the style so that it doesn't need to be recomputed each time but just when one of the values change, I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't sound like a crazy idea

@AydinHassan
Copy link
Member

Looks good to me - like you mentioned privately, requires some updates for the builder and PSR2 fixes. Also would be nice for some tests and this breaks a lot of the existing tests as well. I can help out on Monday if necessary.

@codecov-io
Copy link

codecov-io commented May 4, 2018

Codecov Report

Merging #100 into master will decrease coverage by 0.14%.
The diff coverage is 91.93%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #100      +/-   ##
============================================
- Coverage     96.32%   96.18%   -0.15%     
- Complexity      307      337      +30     
============================================
  Files            23       23              
  Lines           926     1049     +123     
============================================
+ Hits            892     1009     +117     
- Misses           34       40       +6
Impacted Files Coverage Δ Complexity Δ
src/CliMenu.php 90.64% <76.92%> (-0.99%) 74 <0> (+4)
src/MenuStyle.php 93.93% <92.94%> (-0.76%) 60 <22> (+21)
src/CliMenuBuilder.php 98.31% <96.15%> (-0.38%) 53 <6> (+6)
src/Util/ColourUtil.php 100% <0%> (+23.52%) 8% <0%> (-1%) ⬇️

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 3f2ab1e...cfa7953. Read the comment docs.

@@ -265,6 +265,36 @@ public function setTitleSeparator(string $separator) : self
return $this;
}

public function setBorder(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're missing the MenuStyle configuring which should be done in buildStyle()

{
return $this->borderColour;
}
public function getBorderColourCode() : string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line between each of these methods

@AydinHassan AydinHassan added this to the 3.0 milestone May 4, 2018
@Lynesth
Copy link
Collaborator Author

Lynesth commented May 5, 2018

Ok so the only that's missing are tests of actually outputing a menu with borders (that will hit those missing lines in codecov).

I juste really didn't know where to do that (didn't find any tests that check that margin and paddings have an real effect on output, otherwise I would have pu that there).

I may still make some adjustments to the code for optimization so don't merge it right away.

The next step would be to add borders to dialogues I guess.

@AydinHassan
Copy link
Member

AydinHassan commented May 5, 2018

This is looking good to me. I can add the tests after if you would like? Also we can do the border for inputs/dialogues as another PR, nicer to keep these features small and easier to review :) Let me know when your done and we get this merged.

@Lynesth
Copy link
Collaborator Author

Lynesth commented May 6, 2018

I'll try to pre generate the top and bottom borders instead of doing it each time the frame is updated before pushing.

@Lynesth
Copy link
Collaborator Author

Lynesth commented May 7, 2018

Closing/Reopening to trigger travis.

@Lynesth Lynesth closed this May 7, 2018
@Lynesth Lynesth reopened this May 7, 2018
$this->style['borderBottomWidth'] = $bottomWidth;
$this->style['borderLeftWidth'] = $leftWidth;

if (is_string($colour)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw an exception if colour is not null and not a string? validateColour will check the colour later but not if someone does something weird like pass an object to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* @var string
*/
private $borderColour = 'white';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably drop this assignment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I drop it I get an error in generateBorderRows when the border colour isn't set.
Juste like the issue you had with bg and fg colours earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - It works fine for me as private $borderColour. It is set in the constructor from $defaultStyleValues

str_repeat(' ', $this->margin)
);

$this->borderTopRows = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do something like the following if you wanted:

$this->borderTopRows = array_fill(0, $this->borderTopWidth, $borderRow)

Your call, I don't mind :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I'll do that good call


public function getBorderColourCode() : string
{
if (ctype_digit($this->borderColour)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this if statement needs to be negated

@AydinHassan AydinHassan merged commit d7bebfd into php-school:master May 7, 2018
@AydinHassan
Copy link
Member

Thank you @Lynesth - this is awesome!

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