11<?php
22namespace jblond \cli ;
33
4+ use InvalidArgumentException ;
5+
46/**
57 * Class CliColors
68 *
@@ -15,6 +17,7 @@ class CliColors {
1517 private $ foregroundColors = array (
1618 'black ' => '0;30 ' ,
1719 'dark_gray ' => '5;30 ' ,
20+ 'grey ' => '5;30 ' ,
1821 'red ' => '1;31 ' ,
1922 'light_red ' => '1;31 ' ,
2023 'green ' => '0;32 ' ,
@@ -50,21 +53,19 @@ class CliColors {
5053 * @param null|string $foregroundColor
5154 * @param null|string $backgroundColor
5255 * @return string
53- * @throws \ InvalidArgumentException
56+ * @throws InvalidArgumentException
5457 */
5558 public function getColoredString ($ string , $ foregroundColor = null , $ backgroundColor = null ){
5659 $ coloredString = '' ;
5760
5861 if (!isset ($ this ->foregroundColors ["$ foregroundColor " ])){
59- throw new \ InvalidArgumentException (sprintf ('Invalid option specified: "%s". Expected one of (%s). ' , $ foregroundColor , implode (', ' , array_keys ($ this ->foregroundColors ))));
62+ throw new InvalidArgumentException (sprintf ('Invalid option specified: "%s". Expected one of (%s). ' , $ foregroundColor , implode (', ' , array_keys ($ this ->foregroundColors ))));
6063 }
6164
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 ))));
65+ $ coloredString .= "\033[ " . $ this ->foregroundColors [$ foregroundColor ] . "m " ;
66+ if (isset ($ this ->backgroundColors ["$ backgroundColor " ])) {
67+ $ coloredString .= "\033[ " . $ this ->backgroundColors [$ backgroundColor ] . "m " ;
6468 }
65-
66- $ coloredString .= "\033[ " . $ this ->foregroundColors [$ foregroundColor ] . "m " ;
67- $ coloredString .= "\033[ " . $ this ->backgroundColors [$ backgroundColor ] . "m " ;
6869 $ coloredString .= $ string . "\033[0m " ;
6970 return $ coloredString ;
7071 }
0 commit comments