Skip to content

Commit efdfcdc

Browse files
author
Automated Development
committed
force correct colors
1 parent 2e3f93d commit efdfcdc

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

example/colors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
$cli->output(
1717
$colors->getColoredString($color . ' on ' . $bgColor, $color, $bgColor)
1818
);
19-
$cli->output($colors->getColoredString(' ', 'default', 'default'));
19+
$cli->output($colors->getColoredString(' ', 'black', 'black'));
2020
}
2121
}

src/jblond/cli/CliColors.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,21 @@ class CliColors {
5050
* @param null|string $foregroundColor
5151
* @param null|string $backgroundColor
5252
* @return string
53+
* @throws \InvalidArgumentException
5354
*/
5455
public function getColoredString($string, $foregroundColor = null, $backgroundColor = null){
5556
$coloredString = '';
5657

57-
if(isset($this->foregroundColors["$foregroundColor"])){
58-
$coloredString .= "\033[" . $this->foregroundColors[$foregroundColor] . "m";
58+
if(!isset($this->foregroundColors["$foregroundColor"])){
59+
throw new \InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s).', $foregroundColor, implode(', ', array_keys($this->foregroundColors))));
5960
}
6061

61-
if(isset($this->backgroundColors["$backgroundColor"])){
62-
$coloredString .= "\033[" . $this->backgroundColors[$backgroundColor] . "m";
62+
if(!isset($this->backgroundColors["$backgroundColor"])){
63+
throw new \InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s).', $backgroundColor, implode(', ', array_keys($this->backgroundColors))));
6364
}
6465

66+
$coloredString .= "\033[" . $this->foregroundColors[$foregroundColor] . "m";
67+
$coloredString .= "\033[" . $this->backgroundColors[$backgroundColor] . "m";
6568
$coloredString .= $string . "\033[0m";
6669
return $coloredString;
6770
}

0 commit comments

Comments
 (0)