Skip to content

Commit

Permalink
fix(angular): update color
Browse files Browse the repository at this point in the history
  • Loading branch information
thepercival committed May 1, 2022
1 parent da31d2b commit 20cef4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 44 deletions.
24 changes: 24 additions & 0 deletions domain/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,28 @@ public function outputString(string|int $value, int $minLength = null, Color|nul
}
$this->logger->info(Color::getColored($color, $str));
}

public function convertNumberToColor(int $number): Color
{
switch ($number) {
case 1:
return Color::Red;
case 2:
return Color::Green;
case 3:
return Color::Yellow;
case 4:
return Color::Blue;
case 5:
return Color::Magenta;
case 6:
return Color::Cyan;
case 7:
case 8:
case 9:
case 0:
return Color::White;
}
throw new \Exception('number must be 0-9', E_ERROR);
}
}
48 changes: 4 additions & 44 deletions domain/Output/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,20 @@ enum Color: string
{
case Red = '0;31';
case Green = '0;32';
case Yellow = '0;33';
case Blue = '0;34';
case Yellow = '1;33';
case Purple = '0;35';
case LightGray = '0;37';
case Magenta = '0;35';
case Cyan = '0;36';
case LightGreen = '1;32';
case LightCyan = '1;36';
case White = '1;37';
// 'black'] = '0;30';
// 'dark_gray'] = '1;30';
// 'green'] = ;
// 'light_red'] = '1;31';
// 'purple'] = '0;35';
// 'light_purple'] = '1;35';
// 'brown'] = '0;33';

// } elseif ($number === Output::COLOR_GRAY) {
// $sColor = '0;37'; // light_gray
case White = '0;37';

public static function getColored(Color|null $color, string $content): string
{
if( $color === null ) {
if ($color === null) {
return $content;
}
$coloredString = "\033[" . $color->value . "m";
return $coloredString . $content . "\033[0m";
}

public static function convertNumberToColor(int $number): Color
{
switch ($number) {
case 1:
return Color::Red; // '#298F00';
case 2:
return Color::Green; // '#84CF96';
case 3:
return Color::Blue; // '#0588BC';
case 4:
return Color::Yellow; // '#00578A';
case 5:
return Color::Purple; // '#298F00';
case 6:
return Color::LightGray; // '#84CF96';
case 7:
return Color::Cyan; // '#0588BC';
case 8:
return Color::LightGreen; // '#00578A';
case 9:
return Color::LightCyan; // '#00578A';
case 0:
return Color::White;
}
throw new \Exception('number must be 0-9', E_ERROR);
}
}

/*
Expand Down

0 comments on commit 20cef4b

Please sign in to comment.