Skip to content

Modification of colours rendering + 256 colours support #104

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

Merged
merged 43 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
179088f
Optimization of colours rendering + 256 colours
Lynesth May 5, 2018
853ae74
Modification of colours sequences rendering
Lynesth May 5, 2018
8ab7a58
Fix typo and typehint
Lynesth May 5, 2018
6a13666
Add new logic for 256 colours
Lynesth May 5, 2018
b0fdb2a
Fix missing variables in use ()
Lynesth May 5, 2018
a726534
Modification of colour sequence rendering
Lynesth May 5, 2018
8dfdb09
Add invertedColoursUnsetCode
Lynesth May 5, 2018
7a5a494
Mod of colours sequences
Lynesth May 5, 2018
10fbba4
Typo
Lynesth May 5, 2018
34586bf
Mod colours sequences
Lynesth May 5, 2018
424a59d
Mod colours sequences
Lynesth May 5, 2018
e644200
Adding fallback colours
Lynesth May 6, 2018
4fec147
Add colour fallback
Lynesth May 6, 2018
6bc05dd
Fix elseif
Lynesth May 6, 2018
04da0c5
Add 256 colours tests
Lynesth May 6, 2018
2eddc93
Typo
Lynesth May 6, 2018
6737c74
Modified $fg and $bg comment typehint
Lynesth May 6, 2018
21c16e9
Remove getFb and getBg return type declaration
Lynesth May 6, 2018
98bade7
add getColourSupport to mock terminal
Lynesth May 7, 2018
ed5ea04
Fix test (mixed up fg anf bg)
Lynesth May 7, 2018
d422b6f
InvalidArgumentException for invalid colour codes
Lynesth May 7, 2018
a659040
Add exceptions tests
Lynesth May 7, 2018
2ac6a1c
Fix Set/Unset Codes tests to use new functions
Lynesth May 7, 2018
98ea407
InvalidArgumentException for invalid colour codes
Lynesth May 7, 2018
a051c1b
Add tests for CliMenuBuilder
Lynesth May 7, 2018
c98a35c
Fix whitespace
Lynesth May 7, 2018
84be171
Whitespace + mixed up fg/bg
Lynesth May 7, 2018
b3449c5
Create ColourUtil.php
Lynesth May 7, 2018
58ad5f6
typo
Lynesth May 7, 2018
888700a
Update ColourUtil.php
Lynesth May 7, 2018
f367794
Update ColourUtil.php
Lynesth May 7, 2018
3344690
Add Assertion
Lynesth May 7, 2018
70c7e1f
Use ColourUtil
Lynesth May 7, 2018
5fabca1
Use ColourUtil and remove getAvailableColours
Lynesth May 7, 2018
920f3f5
typo
Lynesth May 7, 2018
c86bd38
Missing 'static'
Lynesth May 7, 2018
065b1b5
Fix variable name
Lynesth May 7, 2018
405a571
Fix PSR2
Lynesth May 7, 2018
e3f9b64
Fix logic
Lynesth May 7, 2018
3fd628a
Fixing tests
Lynesth May 7, 2018
dc3f0b5
Forgot 'default' color name
Lynesth May 7, 2018
a5997fd
Merge branch 'master' into patch-17
Lynesth May 7, 2018
be09a76
Fix whitespace
Lynesth May 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/CliMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,23 +353,22 @@ protected function drawMenuItem(MenuItemInterface $item, bool $selected = false)
{
$rows = $item->getRows($this->style, $selected);

$setColour = $selected
? $this->style->getSelectedSetCode()
: $this->style->getUnselectedSetCode();
$setColour = $this->style->getColoursSetCode();
$resetColour = $this->style->getColoursResetCode();
$invertedColour = $selected
? $this->style->getInvertedColoursSetCode()
: '';

$unsetColour = $selected
? $this->style->getSelectedUnsetCode()
: $this->style->getUnselectedUnsetCode();

return array_map(function ($row) use ($setColour, $unsetColour) {
return array_map(function ($row) use ($setColour, $invertedColour, $resetColour) {
return sprintf(
"%s%s%s%s%s%s%s\n",
"%s%s%s%s%s%s%s%s\n",
str_repeat(' ', $this->style->getMargin()),
$setColour,
$invertedColour,
str_repeat(' ', $this->style->getPadding()),
$row,
str_repeat(' ', $this->style->getRightHandPadding(mb_strlen(s::stripAnsiEscapeSequence($row)))),
$unsetColour,
$resetColour,
str_repeat(' ', $this->style->getMargin())
);
}, $rows);
Expand Down
21 changes: 13 additions & 8 deletions src/CliMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpSchool\CliMenu\MenuItem\SelectableItem;
use PhpSchool\CliMenu\MenuItem\StaticItem;
use PhpSchool\CliMenu\Terminal\TerminalFactory;
use PhpSchool\CliMenu\Util\ColourUtil;
use Assert\Assertion;
use PhpSchool\Terminal\Terminal;
use RuntimeException;
Expand Down Expand Up @@ -198,20 +199,24 @@ public function setExitButtonText(string $exitButtonText) : self
return $this;
}

public function setBackgroundColour(string $colour) : self
public function setBackgroundColour($colour, string $fallback = null) : self
{
Assertion::inArray($colour, MenuStyle::getAvailableColours());

$this->style['bg'] = $colour;
$this->style['bg'] = ColourUtil::validateColour(
$this->terminal,
$colour,
$fallback
);

return $this;
}

public function setForegroundColour(string $colour) : self
public function setForegroundColour($colour, string $fallback = null) : self
{
Assertion::inArray($colour, MenuStyle::getAvailableColours());

$this->style['fg'] = $colour;
$this->style['fg'] = ColourUtil::validateColour(
$this->terminal,
$colour,
$fallback
);

return $this;
}
Expand Down
20 changes: 9 additions & 11 deletions src/Dialogue/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function display(string $confirmText = 'OK') : void

$this->write(sprintf(
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
$this->style->getColoursSetCode(),
str_repeat(' ', $this->style->getPadding()),
$this->text,
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
$this->style->getColoursResetCode()
));

$this->emptyRow();
Expand All @@ -39,25 +39,23 @@ public function display(string $confirmText = 'OK') : void
$leftFill = ($promptWidth / 2) - (mb_strlen($confirmText) / 2);

$this->write(sprintf(
"%s%s%s%s%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
"%s%s%s%s%s%s%s\n",
$this->style->getColoursSetCode(),
str_repeat(' ', $leftFill),
$this->style->getUnselectedUnsetCode(),
$this->style->getSelectedSetCode(),
$this->style->getInvertedColoursSetCode(),
$confirmText,
$this->style->getSelectedUnsetCode(),
$this->style->getUnselectedSetCode(),
$this->style->getInvertedColoursUnsetCode(),
str_repeat(' ', ceil($promptWidth - $leftFill - mb_strlen($confirmText))),
$this->style->getUnselectedUnsetCode()
$this->style->getColoursResetCode()
));

$this->write(sprintf(
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
$this->style->getColoursSetCode(),
str_repeat(' ', $this->style->getPadding()),
str_repeat(' ', mb_strlen($this->text)),
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
$this->style->getColoursResetCode()
));

$this->terminal->moveCursorToTop();
Expand Down
4 changes: 2 additions & 2 deletions src/Dialogue/Dialogue.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ protected function emptyRow() : void
$this->write(
sprintf(
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
$this->style->getColoursSetCode(),
str_repeat(' ', $this->style->getPadding()),
str_repeat(' ', mb_strlen($this->text)),
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
$this->style->getColoursResetCode()
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Dialogue/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public function display() : void

$this->write(sprintf(
"%s%s%s%s%s\n",
$this->style->getUnselectedSetCode(),
$this->style->getColoursSetCode(),
str_repeat(' ', $this->style->getPadding()),
$this->text,
str_repeat(' ', $this->style->getPadding()),
$this->style->getUnselectedUnsetCode()
$this->style->getColoursResetCode()
));

$this->emptyRow();
Expand Down
12 changes: 5 additions & 7 deletions src/Input/InputIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ private function drawLine(Input $input, string $userInput, string $text) : void

$line = sprintf(
"%s%s%s%s%s\n",
$input->getStyle()->getUnselectedSetCode(),
$input->getStyle()->getColoursSetCode(),
str_repeat(' ', $input->getStyle()->getPadding()),
$text,
str_repeat(' ', $input->getStyle()->getPadding()),
$input->getStyle()->getUnselectedUnsetCode()
$input->getStyle()->getColoursResetCode()
);

$this->terminal->write($line);
Expand Down Expand Up @@ -240,12 +240,10 @@ private function drawInputField(Input $input, string $userInput) : void
$input,
$userInput,
sprintf(
'%s%s%s%s%s',
$input->getStyle()->getUnselectedUnsetCode(),
$input->getStyle()->getSelectedSetCode(),
'%s%s%s',
$input->getStyle()->getInvertedColoursSetCode(),
$userInput,
$input->getStyle()->getSelectedUnsetCode(),
$input->getStyle()->getUnselectedSetCode()
$input->getStyle()->getInvertedColoursUnsetCode()
)
);
}
Expand Down
Loading