├── .codeclimate.json ├── LICENSE ├── README.md ├── composer.json ├── examples.php ├── psalm.xml └── src ├── ANSIColors.php ├── ConsoleArtistGuild.php └── ConsolePainter.php /.codeclimate.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2", 3 | "checks": { 4 | "complex-logic": { 5 | "config": { 6 | "threshold": 7 7 | } 8 | }, 9 | "method-complexity": { 10 | "config": { 11 | "threshold": 10 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2021 PHP Experts, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ConsolePainter 2 | 3 | [![TravisCI](https://travis-ci.org/phpexpertsinc/ConsolePainter.svg?branch=master)](https://travis-ci.org/phpexpertsinc/ConsolePainter) 4 | [![Test Coverage](https://api.codeclimate.com/v1/badges/1eef8c643548226efa69/test_coverage)](https://codeclimate.com/github/phpexpertsinc/ConsolePainter/test_coverage) 5 | 6 | ConsolePainter is a PHP Experts, Inc., Project that enables easy color and stylization of ANSI terminals. 7 | 8 | It strives to conform to the standard ANSI terminal colors as documented at 9 | https://misc.flogisoft.com/bash/tip_colors_and_formatting 10 | 11 | ![image](https://user-images.githubusercontent.com/1125541/59557043-0a774b00-8f95-11e9-87cb-223afd9130ca.png) 12 | 13 | ## Installation 14 | 15 | Via Composer 16 | 17 | ```bash 18 | composer require phpexperts/console-painter 19 | ``` 20 | 21 | ## Usage 22 | 23 | ```php 24 | use PHPExperts\ConsolePainter\ConsolePainter; 25 | 26 | $p = new ConsolePainter(); 27 | 28 | // This is *REALLY* emphasized! 29 | echo "\t" . $p->italics('This is ') . 30 | $p->bold('*') . $p->bold()->underlined()->yellow('*REALLY*') . 31 | $p->bold()->onLightBlue(' emphasized*') . '!' . "\n"; 32 | 33 | echo $p->yellow('Press ')->bolder()->red('ENTER')->yellow(' to continue...') . "\n"; 34 | 35 | echo "\n"; 36 | 37 | // Draw the Red, White and Blue: 38 | echo $p->bolder()->red('Red')->dim(', ')->italics()->white('White ')->dim('and ')->blue('Blue') . "\n"; 39 | ``` 40 | 41 | This will output: 42 | 43 | ![image](https://user-images.githubusercontent.com/1125541/59557118-15cb7600-8f97-11e9-9a0f-dc0b50898f79.png) 44 | 45 | You can even make really complex ASCII art with it. Here is a derivation of 46 | the European Union logo: 47 | 48 | ![image](https://user-images.githubusercontent.com/1125541/59557060-7659b380-8f95-11e9-98df-2a82bbdaae72.png) 49 | 50 | ## Demos 51 | 52 | ### Basic styles: 53 | 54 | ![image](https://user-images.githubusercontent.com/1125541/59557043-0a774b00-8f95-11e9-87cb-223afd9130ca.png) 55 | 56 | ### Complex text styling 57 | 58 | ![image](https://user-images.githubusercontent.com/1125541/59557055-50ccaa00-8f95-11e9-8fa5-d435efc5d688.png) 59 | 60 | ### ASCII Art 61 | 62 | ![image](https://user-images.githubusercontent.com/1125541/59557060-7659b380-8f95-11e9-98df-2a82bbdaae72.png) 63 | 64 | ## Use cases 65 | 66 | ConsolePainter: Stylization 67 | ✔ Can bold text 68 | ✔ Can italicize text 69 | ✔ Can underline text 70 | ✔ Can dim text 71 | ✔ Can blink text 72 | ✔ Can hide text 73 | ✔ Can invert the text style 74 | ✔ All combinations of stylizations work 75 | 76 | ConsolePainter: Foreground Colors 77 | ✔ Can make the text the default color 78 | ✔ Can make the text black 79 | ✔ Can make the text dark grey 80 | ✔ Can make the text blue 81 | ✔ Can make the text light blue 82 | ✔ Can make the text green 83 | ✔ Can make the text light green 84 | ✔ Can make the text cyan 85 | ✔ Can make the text light cyan 86 | ✔ Can make the text red 87 | ✔ Can make the text light red 88 | ✔ Can make the text purple 89 | ✔ Can make the text light purple 90 | ✔ Can make the text brown 91 | ✔ Can make the text yellow 92 | ✔ Can make the text light gray 93 | ✔ Can make the text white 94 | ✔ Can chain two or more colored words together 95 | ✔ Can chain two or more colored words together with a background 96 | ✔ Can make the european union logo 97 | 98 | ## Testing 99 | 100 | ```bash 101 | phpunit --testdox 102 | ``` 103 | 104 | ## Contributors 105 | 106 | [Theodore R. Smith](https://www.phpexperts.pro/]) 107 | GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 108 | CEO: PHP Experts, Inc. 109 | 110 | ## License 111 | 112 | MIT license. Please see the [license file](LICENSE) for more information. 113 | 114 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phpexperts/console-painter", 3 | "description": "A quick and easy library for colorizing and stylizing ANSI consoles.", 4 | "keywords": [ 5 | "console colors", 6 | "bash colors", 7 | "bash formatting", 8 | "terminal colors" 9 | ], 10 | "homepage": "https://www.phpexperts.pro/", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "PHP Experts, Inc.", 15 | "homepage": "https://www.phpexperts.pro/" 16 | }, 17 | { 18 | "name": "Theodore R. Smith", 19 | "homepage": "https://www.linkedin.com/in/tedrsmith" 20 | } 21 | ], 22 | "require": { 23 | "php": ">=7.4", 24 | "ext-json": "*" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "7.*|8.*|9.*", 28 | "mockery/mockery": "^1.0", 29 | "phpstan/phpstan": "*", 30 | "friendsofphp/php-cs-fixer": "*", 31 | "symfony/var-dumper": "*", 32 | "povils/phpmnd": "*", 33 | "squizlabs/php_codesniffer": "*", 34 | "phpexperts/combinatorics": "^1.0" 35 | }, 36 | "autoload": { 37 | "psr-4": { 38 | "PHPExperts\\ConsolePainter\\" : "src/" 39 | } 40 | }, 41 | "autoload-dev": { 42 | "psr-4": { "PHPExperts\\ConsolePainter\\Tests\\" : "tests/" } 43 | }, 44 | "config": { 45 | "classmap-authoritative": true 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /examples.php: -------------------------------------------------------------------------------- 1 | 8 | * GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 9 | * https://www.phpexperts.pro/ 10 | * https://github.com/PHPExpertsInc/ConsolePainter 11 | * 12 | * This file is licensed under the MIT License. 13 | */ 14 | 15 | include __DIR__ . '/vendor/autoload.php'; 16 | 17 | use PHPExperts\ConsolePainter\ConsolePainter; 18 | 19 | $painter = new ConsolePainter(); 20 | 21 | echo $painter->bold() 22 | ->underlined() 23 | ->red('Red ') 24 | ->onDarkGray('Text') 25 | ->text("\n" . 'bold + underlined + white') . "\n"; 26 | 27 | echo "New Text\n"; 28 | 29 | echo $painter->bold() 30 | ->underlined() 31 | ->red() 32 | ->onDarkGray() 33 | ->text('bold + underlined + white') . "\n"; 34 | 35 | $p = $painter; 36 | 37 | echo $p->bold()->italics('Bold italics') . ' ' . $p->red('Bold + Red') . "\n"; 38 | echo "Normal text\n"; 39 | echo $p->black()->onLightCyan(' Black on Light Cyan ') . "\n"; 40 | echo $p->black()->onLightGreen(' Black on Light Green ') . "\n"; 41 | echo $p->white()->onGreen(' White on Green ') . "\n"; 42 | echo $p->bold()->white()->onGreen(' White on Green, Bolded ') . "\n"; 43 | echo $p->bold()->underlined()->white()->onBlue('White on Blue, Bolded + Underlined') . "\n"; 44 | echo "\n"; 45 | 46 | echo $p->onRed()->bold()->yellow(' WARNING!! WARNING!! ') . "\n\n"; 47 | 48 | /** Advanced */ 49 | 50 | echo "\t" . $p->italics('This is ') . 51 | $p->bold('*') . $p->bold()->underlined()->yellow('*REALLY*') . 52 | $p->bold()->onLightBlue(' emphasized*') . '!' . "\n"; 53 | 54 | echo "\n"; 55 | 56 | echo "\t" . $p->yellow('Press ')->bolder()->red('ENTER')->yellow(' to continue...') . "\n"; 57 | 58 | echo "\n"; 59 | 60 | // Draw the Red, White and Blue: 61 | echo "\t" . $p->bolder()->red('Red')->dim(', ')->italics()->white('White ')->dim('and ')->blue('Blue') . "\n"; 62 | 63 | echo "\n"; 64 | 65 | // Draw the European Union logo: 66 | $starField = ' ★ ★ ★ ★ ★ '; 67 | $euroLogo = $p->text("\t")->yellow()->onBlue($starField) . "\n"; 68 | $euroLogo = $p->text((string) $euroLogo . "\t")->onBlue() 69 | ->bold()->yellow(' ★ ')->bolder()->white(' E U ')->onBlue()->yellow(' ★ ') . "\n"; 70 | $euroLogo = $p->text((string) $euroLogo . "\t")->onBlue()->yellow($starField); 71 | echo "$euroLogo\n\n"; 72 | -------------------------------------------------------------------------------- /psalm.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/ANSIColors.php: -------------------------------------------------------------------------------- 1 | 8 | * GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 9 | * https://www.phpexperts.pro/ 10 | * https://github.com/PHPExpertsInc/ConsolePainter 11 | * 12 | * This file is licensed under the MIT License. 13 | */ 14 | 15 | namespace PHPExperts\ConsolePainter; 16 | 17 | interface ANSIColors 18 | { 19 | public const BOLD = '1'; 20 | public const DIM = '2'; 21 | public const ITALICS = '3'; 22 | public const UNDERLINE = '4'; 23 | public const BLINK = '5'; 24 | public const INVERSE = '7'; 25 | public const HIDDEN = '8'; 26 | 27 | public const RESET = '0'; 28 | public const UN_BOLD = '21'; 29 | public const UN_DIM = '22'; 30 | public const UN_ITALICS = '23'; 31 | public const UN_UNDERLINE = '24'; 32 | public const UN_BLINK = '25'; 33 | public const UN_INVERSE = '27'; 34 | public const UN_HIDDEN = '28'; 35 | 36 | public const FG_DEFAULT = '39'; 37 | public const FG_BLACK = '30'; 38 | public const FG_DARK_GRAY = '90'; 39 | public const FG_BLUE = '34'; 40 | public const FG_LIGHT_BLUE = '94'; 41 | public const FG_GREEN = '32'; 42 | public const FG_LIGHT_GREEN = '92'; 43 | public const FG_CYAN = '36'; 44 | public const FG_LIGHT_CYAN = '96'; 45 | public const FG_RED = '31'; 46 | public const FG_LIGHT_RED = '91'; 47 | public const FG_PURPLE = '35'; 48 | public const FG_LIGHT_PURPLE = '95'; 49 | public const FG_BROWN = '0;33'; 50 | public const FG_YELLOW = '1;33'; 51 | public const FG_LIGHT_GRAY = '37'; 52 | public const FG_WHITE = '97'; 53 | 54 | public const BG_DEFAULT = '49'; 55 | public const BG_BLACK = '40'; 56 | public const BG_RED = '41'; 57 | public const BG_GREEN = '42'; 58 | public const BG_YELLOW = '43'; 59 | public const BG_BLUE = '44'; 60 | public const BG_PURPLE = '45'; 61 | public const BG_CYAN = '46'; 62 | public const BG_LIGHT_GRAY = '47'; 63 | public const BG_DARK_GRAY = '100'; 64 | public const BG_LIGHT_RED = '101'; 65 | public const BG_LIGHT_GREEN = '102'; 66 | public const BG_LIGHT_YELLOW = '103'; 67 | public const BG_LIGHT_BLUE = '104'; 68 | public const BG_LIGHT_PURPLE = '105'; 69 | public const BG_LIGHT_CYAN = '106'; 70 | public const BG_WHITE = '107'; 71 | } 72 | -------------------------------------------------------------------------------- /src/ConsoleArtistGuild.php: -------------------------------------------------------------------------------- 1 | 8 | * GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 9 | * https://www.phpexperts.pro/ 10 | * https://github.com/PHPExpertsInc/ConsolePainter 11 | * 12 | * This file is licensed under the MIT License. 13 | */ 14 | 15 | namespace PHPExperts\ConsolePainter; 16 | 17 | interface ConsoleArtistGuild 18 | { 19 | public function bold(?string $text = null): self; 20 | public function bolder(?string $text = null): self; 21 | public function dim(?string $text = null): self; 22 | public function italics(?string $text = null): self; 23 | public function underlined(?string $text = null): self; 24 | public function blink(?string $text = null): self; 25 | public function inverse(?string $text = null): self; 26 | public function hidden(?string $text = null): self; 27 | 28 | // --- Foregrounds --- // 29 | public function defaultColor(?string $text = null): self; 30 | public function black(?string $text = null): self; 31 | public function darkGray(?string $text = null): self; 32 | public function blue(?string $text = null): self; 33 | public function lightBlue(?string $text = null): self; 34 | public function green(?string $text = null): self; 35 | public function lightGreen(?string $text = null): self; 36 | public function cyan(?string $text = null): self; 37 | public function lightCyan(?string $text = null): self; 38 | public function red(?string $text = null): self; 39 | public function lightRed(?string $text = null): self; 40 | public function purple(?string $text = null): self; 41 | public function lightPurple(?string $text = null): self; 42 | public function brown(?string $text = null): self; 43 | public function yellow(?string $text = null): self; 44 | public function lightGray(?string $text = null): self; 45 | public function white(?string $text = null): self; 46 | 47 | // --- Backgrounds --- // 48 | public function onDefaultColor(?string $text = null): ConsoleArtistGuild; 49 | public function onBlack(?string $text = null): self; 50 | public function onRed(?string $text = null): self; 51 | public function onGreen(?string $text = null): self; 52 | public function onYellow(?string $text = null): self; 53 | public function onBlue(?string $text = null): self; 54 | public function onPurple(?string $text = null): self; 55 | public function onCyan(?string $text = null): self; 56 | public function onLightGray(?string $text = null): self; 57 | public function onDarkGray(?string $text = null): self; 58 | public function onLightRed(?string $text = null): self; 59 | public function onLightGreen(?string $text = null): self; 60 | public function onLightYellow(?string $text = null): self; 61 | public function onLightBlue(?string $text = null): self; 62 | public function onLightPurple(?string $text = null): self; 63 | public function onLightCyan(?string $text = null): self; 64 | public function onWhite(?string $text = null): self; 65 | 66 | public function text(string $text): self; 67 | public function __toString(): string; 68 | } 69 | -------------------------------------------------------------------------------- /src/ConsolePainter.php: -------------------------------------------------------------------------------- 1 | 8 | * GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 9 | * https://www.phpexperts.pro/ 10 | * https://github.com/PHPExpertsInc/ConsolePainter 11 | * 12 | * This file is licensed under the MIT License. 13 | */ 14 | 15 | namespace PHPExperts\ConsolePainter; 16 | 17 | class ConsolePainter implements ConsoleArtistGuild, ANSIColors 18 | { 19 | public string $e = "\e"; 20 | 21 | /** @var string[] */ 22 | protected array $applied = []; 23 | 24 | /** @var string[] */ 25 | protected array $reverseApplied = []; 26 | 27 | protected string $line = ''; 28 | 29 | protected string $text = ''; 30 | 31 | protected function applyFormat(string $apply, ?string $undo, ?string $text = null): ConsoleArtistGuild 32 | { 33 | $this->applied[] = $apply; 34 | if ($undo !== null) { 35 | $this->reverseApplied[] = $undo; 36 | } 37 | 38 | if ($text !== null) { 39 | $applied = implode(';', $this->applied); 40 | $reversed = implode(';', $this->reverseApplied); 41 | $this->text .= "{$this->e}[{$applied}m{$text}{$this->e}[{$reversed}m"; 42 | $this->applied = []; 43 | $this->reverseApplied = []; 44 | } 45 | 46 | return $this; 47 | } 48 | 49 | // --- Stylers --- // 50 | public function bold(?string $text = null): ConsoleArtistGuild 51 | { 52 | return $this->applyFormat(self::BOLD, self::UN_BOLD, $text); 53 | } 54 | 55 | public function bolder(?string $text = null): ConsoleArtistGuild 56 | { 57 | return $this->applyFormat(self::UN_BOLD, '', $text); 58 | } 59 | 60 | public function dim(?string $text = null): ConsoleArtistGuild 61 | { 62 | return $this->applyFormat(self::DIM, self::UN_DIM, $text); 63 | } 64 | 65 | public function italics(?string $text = null): ConsoleArtistGuild 66 | { 67 | return $this->applyFormat(self::ITALICS, self::UN_ITALICS, $text); 68 | } 69 | 70 | public function underlined(?string $text = null): ConsoleArtistGuild 71 | { 72 | return $this->applyFormat(self::UNDERLINE, self::UN_UNDERLINE, $text); 73 | } 74 | 75 | public function blink(?string $text = null): ConsoleArtistGuild 76 | { 77 | return $this->applyFormat(self::BLINK, self::UN_BLINK, $text); 78 | } 79 | 80 | public function inverse(?string $text = null): ConsoleArtistGuild 81 | { 82 | return $this->applyFormat(self::INVERSE, self::UN_INVERSE, $text); 83 | } 84 | 85 | public function hidden(?string $text = null): ConsoleArtistGuild 86 | { 87 | return $this->applyFormat(self::HIDDEN, self::UN_HIDDEN, $text); 88 | } 89 | 90 | // --- Foregrounds --- // 91 | public function defaultColor(?string $text = null): ConsoleArtistGuild 92 | { 93 | return $this->applyFormat(self::FG_DEFAULT, self::FG_DEFAULT, $text); 94 | } 95 | 96 | public function black(?string $text = null): ConsoleArtistGuild 97 | { 98 | return $this->applyFormat(self::FG_BLACK, self::FG_DEFAULT, $text); 99 | } 100 | 101 | public function darkGray(?string $text = null): ConsoleArtistGuild 102 | { 103 | return $this->applyFormat(self::FG_DARK_GRAY, self::FG_DEFAULT, $text); 104 | } 105 | 106 | public function blue(?string $text = null): ConsoleArtistGuild 107 | { 108 | return $this->applyFormat(self::FG_BLUE, self::FG_DEFAULT, $text); 109 | } 110 | 111 | public function lightBlue(?string $text = null): ConsoleArtistGuild 112 | { 113 | return $this->applyFormat(self::FG_LIGHT_BLUE, self::FG_DEFAULT, $text); 114 | } 115 | 116 | public function green(?string $text = null): ConsoleArtistGuild 117 | { 118 | return $this->applyFormat(self::FG_GREEN, self::FG_DEFAULT, $text); 119 | } 120 | 121 | public function lightGreen(?string $text = null): ConsoleArtistGuild 122 | { 123 | return $this->applyFormat(self::FG_LIGHT_GREEN, self::FG_DEFAULT, $text); 124 | } 125 | 126 | public function cyan(?string $text = null): ConsoleArtistGuild 127 | { 128 | return $this->applyFormat(self::FG_CYAN, self::FG_DEFAULT, $text); 129 | } 130 | 131 | public function lightCyan(?string $text = null): ConsoleArtistGuild 132 | { 133 | return $this->applyFormat(self::FG_LIGHT_CYAN, self::FG_DEFAULT, $text); 134 | } 135 | 136 | public function red(?string $text = null): ConsoleArtistGuild 137 | { 138 | return $this->applyFormat(self::FG_RED, self::FG_DEFAULT, $text); 139 | } 140 | 141 | public function lightRed(?string $text = null): ConsoleArtistGuild 142 | { 143 | return $this->applyFormat(self::FG_LIGHT_RED, self::FG_DEFAULT, $text); 144 | } 145 | 146 | public function purple(?string $text = null): ConsoleArtistGuild 147 | { 148 | return $this->applyFormat(self::FG_PURPLE, self::FG_DEFAULT, $text); 149 | } 150 | 151 | public function lightPurple(?string $text = null): ConsoleArtistGuild 152 | { 153 | return $this->applyFormat(self::FG_LIGHT_PURPLE, self::FG_DEFAULT, $text); 154 | } 155 | 156 | public function brown(?string $text = null): ConsoleArtistGuild 157 | { 158 | return $this->applyFormat(self::FG_BROWN, self::FG_DEFAULT, $text); 159 | } 160 | 161 | public function yellow(?string $text = null): ConsoleArtistGuild 162 | { 163 | return $this->applyFormat(self::FG_YELLOW, self::UN_BOLD . ';' . self::FG_DEFAULT, $text); 164 | } 165 | 166 | public function lightGray(?string $text = null): ConsoleArtistGuild 167 | { 168 | return $this->applyFormat(self::FG_LIGHT_GRAY, self::FG_DEFAULT, $text); 169 | } 170 | 171 | public function white(?string $text = null): ConsoleArtistGuild 172 | { 173 | return $this->applyFormat(self::FG_WHITE, self::FG_DEFAULT, $text); 174 | } 175 | 176 | // --- Backgrounds --- // 177 | public function onDefaultColor(?string $text = null): ConsoleArtistGuild 178 | { 179 | return $this->applyFormat(self::BG_DEFAULT, null, $text); 180 | } 181 | 182 | public function onBlack(?string $text = null): ConsoleArtistGuild 183 | { 184 | return $this->applyFormat(self::BG_BLACK, null, $text); 185 | } 186 | 187 | public function onRed(?string $text = null): ConsoleArtistGuild 188 | { 189 | return $this->applyFormat(self::BG_RED, null, $text); 190 | } 191 | 192 | public function onGreen(?string $text = null): ConsoleArtistGuild 193 | { 194 | return $this->applyFormat(self::BG_GREEN, null, $text); 195 | } 196 | 197 | public function onYellow(?string $text = null): ConsoleArtistGuild 198 | { 199 | return $this->applyFormat(self::BG_YELLOW, null, $text); 200 | } 201 | 202 | public function onBlue(?string $text = null): ConsoleArtistGuild 203 | { 204 | return $this->applyFormat(self::BG_BLUE, null, $text); 205 | } 206 | 207 | public function onPurple(?string $text = null): ConsoleArtistGuild 208 | { 209 | return $this->applyFormat(self::BG_PURPLE, null, $text); 210 | } 211 | 212 | public function onCyan(?string $text = null): ConsoleArtistGuild 213 | { 214 | return $this->applyFormat(self::BG_CYAN, null, $text); 215 | } 216 | 217 | public function onLightGray(?string $text = null): ConsoleArtistGuild 218 | { 219 | return $this->applyFormat(self::BG_LIGHT_GRAY, null, $text); 220 | } 221 | 222 | public function onDarkGray(?string $text = null): ConsoleArtistGuild 223 | { 224 | return $this->applyFormat(self::BG_DARK_GRAY, null, $text); 225 | } 226 | 227 | public function onLightRed(?string $text = null): ConsoleArtistGuild 228 | { 229 | return $this->applyFormat(self::BG_LIGHT_RED, null, $text); 230 | } 231 | 232 | public function onLightGreen(?string $text = null): ConsoleArtistGuild 233 | { 234 | return $this->applyFormat(self::BG_LIGHT_GREEN, null, $text); 235 | } 236 | 237 | public function onLightYellow(?string $text = null): ConsoleArtistGuild 238 | { 239 | return $this->applyFormat(self::BG_LIGHT_YELLOW, null, $text); 240 | } 241 | 242 | public function onLightBlue(?string $text = null): ConsoleArtistGuild 243 | { 244 | return $this->applyFormat(self::BG_LIGHT_BLUE, null, $text); 245 | } 246 | 247 | public function onLightPurple(?string $text = null): ConsoleArtistGuild 248 | { 249 | return $this->applyFormat(self::BG_LIGHT_PURPLE, null, $text); 250 | } 251 | 252 | public function onLightCyan(?string $text = null): ConsoleArtistGuild 253 | { 254 | return $this->applyFormat(self::BG_LIGHT_CYAN, null, $text); 255 | } 256 | 257 | public function onWhite(?string $text = null): ConsoleArtistGuild 258 | { 259 | return $this->applyFormat(self::BG_WHITE, null, $text); 260 | } 261 | 262 | public function text(string $text): self 263 | { 264 | $this->applyFormat('', '', $text); 265 | 266 | return $this; 267 | } 268 | 269 | public function __toString(): string 270 | { 271 | $text = $this->text . "{$this->e}[0m"; 272 | $this->text = ''; 273 | 274 | return $text; 275 | } 276 | } 277 | --------------------------------------------------------------------------------