Skip to content

Commit 585ee6e

Browse files
authored
Merge pull request #14 from macocci7/add_attributes
Add attributes
2 parents 9a241d4 + 65e0d0b commit 585ee6e

15 files changed

Lines changed: 851 additions & 40 deletions

README.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ composer require macocci7/bash-colorizer
123123
->echo("Hi, there!", PHP_EOL);
124124
```
125125

126+
by hex code:
127+
```php
128+
Colorizer::foreground('#ffcc00') // or #fc0
129+
->echo("Hi, there!", PHP_EOL);
130+
```
131+
126132
by number [0 - 255] (256 colors):
127133
```php
128134
Colorizer::foreground(2)
@@ -145,6 +151,12 @@ composer require macocci7/bash-colorizer
145151
->echo("Hi, there!", PHP_EOL);
146152
```
147153

154+
by hex code:
155+
```php
156+
Colorizer::background("#ffcc00") // or #fc0
157+
->echo("Hi, there!", PHP_EOL);
158+
```
159+
148160
by number [0 - 255] (256 colors):
149161
```php
150162
Colorizer::background(1)
@@ -168,6 +180,28 @@ composer require macocci7/bash-colorizer
168180
->echo("Hi, there!", PHP_EOL);
169181
```
170182

183+
- Setting underline color:
184+
185+
by hex code:
186+
```php
187+
Colorizer::underline("#ffcc00") // or #fc0
188+
->echo("Hi, there!", PHP_EOL);
189+
```
190+
191+
by number [0 - 255] (256 colors):
192+
```php
193+
Colorizer::underline(1)
194+
->echo("Hi, there!", PHP_EOL);
195+
```
196+
197+
by (RGB) array (24bit 16777216 colors):
198+
```php
199+
Colorizer::underline([255, 0, 0])
200+
->echo("Hi, there!", PHP_EOL);
201+
```
202+
203+
See more: [Available Colors](#63-available-colors)
204+
171205
- Returning colorized string:
172206

173207
As an argument of echo:
@@ -223,22 +257,34 @@ composer require macocci7/bash-colorizer
223257
|`no-italic`|〇|〇|
224258
|`no-underline`|〇|〇|
225259
|`no-blink`|ー<br><a href="#note3">*3</a>|〇<br><a href="#note4">*4</a>|
260+
|`proportional-spacing`|ー|ー|
226261
|`no-reverse`|〇|〇|
227262
|`no-conceal`|〇|〇|
228263
|`no-strike`|〇|〇|
264+
|`no-proportional-spacing`|ー|ー|
265+
|`framed`|❌|❌|
266+
|`encircled`|❌|❌|
267+
|`overlined`|〇|〇|
268+
|`no-framed-no-encircled`|ー<br><a href="#note3">*3</a>|ー<br><a href="#note3">*3</a>|
269+
|`no-overlined`|〇|〇|
270+
|`underline-color`|〇|▲<br><a href="#note5">*5</a>|
229271

230272
> <a id="note1"></a>
231273
*1: No effect with `faint`<br>
232274
> <a id="note2"></a>
233275
*2: Not `fast` (blinks at the same rate as `blink`)<br>
234276
> <a id="note3"></a>
235-
*3: Unknown because `blink` has no effect<br>
277+
*3: Unknown because the corresponding attribute has no effect<br>
236278
> <a id="note4"></a>
237279
*4: Also effective against `fast-blink`<br>
280+
> <a id="note5"></a>
281+
*5: Partially effective<br>
238282

239283
e.g.) on VSCode Terminal
240284

241-
<img src="arts/available_attributes.png" width="180" height="360" />
285+
<img src="arts/available_attributes.png" width="220" height="515" />
286+
287+
See more: [Select Graphic Rendition parameters | ANSI escape code | Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#Select_Graphic_Rendition_parameters)
242288

243289
### 6.3. Available Colors
244290

@@ -261,7 +307,7 @@ e.g.) on VSCode Terminal
261307
|---|---|
262308
|<img src="arts/available_foreground_colors.png" with="240" height="216" />|<img src="arts/available_background_colors.png" with="240" height="216" />|
263309

264-
- 256 colors [ 0 - 255 ]:
310+
- 256 colors [ 0 - 255 ]: `foreground`/`background`/`underline`
265311

266312
e.g.) foreground colors on VSCode Terminal:
267313

@@ -271,6 +317,10 @@ e.g.) on VSCode Terminal
271317

272318
<img src="arts/background_256colors.png" width="500" height="256" />
273319

320+
e.g.) underline colors on VSCode Terminal:
321+
322+
<img src="arts/underline_256colors.png" width="500" height="252" />
323+
274324
- 24bit (16777216) colors:
275325

276326
e.g.) foreground colors on VSCode Terminal:
@@ -281,6 +331,10 @@ e.g.) on VSCode Terminal
281331

282332
<img src="arts/background_24bitcolors.png" width="500" height="406"/>
283333

334+
e.g.) underline colors on VSCode Terminal:
335+
336+
<img src="arts/underline_24bitcolors.png" width="500" height="410"/>
337+
284338
## 7. Examples
285339

286340
Example codes are in [playground](playground/) directory.
@@ -293,6 +347,8 @@ Example codes are in [playground](playground/) directory.
293347
- [foreground_24bitcolors.php](playground/foreground_24bitcolors.php)
294348
- [background_256colors.php](playground/background_256colors.php)
295349
- [background_24bitcolors.php](playground/background_24bitcolors.php)
350+
- [underline_256colors.php](playground/underline_256colors.php)
351+
- [underline_24bitcolors.php](playground/underline_24bitcolors.php)
296352
- [readable.php](playground/readable.php)
297353

298354
## 8. LICENSE

arts/available_attributes.png

12.1 KB
Loading

arts/underline_24bitcolors.png

165 KB
Loading

arts/underline_256colors.png

49.3 KB
Loading

playground/colorizer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
$greeting = "Let's make your bash terminal full of colors!";
88

99
Colorizer::attributes(["bold"])
10+
->echo(PHP_EOL)
1011
->foreground("red")->echo(" B ")
1112
->foreground("yellow")->echo("A ")
1213
->foreground("white")->echo("S ")
@@ -19,7 +20,8 @@
1920
->foreground("yellow")->echo("I ")
2021
->foreground("white")->echo("Z ")
2122
->foreground("green")->echo("E ")
22-
->foreground("cyan")->echo("R", "\n\n")
23+
->foreground("cyan")->echo("R", PHP_EOL)
24+
->echo(PHP_EOL)
2325
;
2426
Colorizer::attributes(["reset"])
2527
->foreground("white")->background("black")->echo($greeting, PHP_EOL)
@@ -30,4 +32,5 @@
3032
->foreground("green")->background("cyan")->echo($greeting, PHP_EOL)
3133
->foreground("green")->background("blue")->echo($greeting, PHP_EOL)
3234
->foreground("green")->background("magenta")->echo($greeting, PHP_EOL)
35+
->echo('', PHP_EOL)
3336
;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
use Macocci7\BashColorizer\Colorizer;
6+
7+
$interval = 64;
8+
$column = 5;
9+
$i = 0;
10+
11+
for ($r = 0; $r <= 256; $r += $interval) {
12+
for ($g = 0; $g <= 256; $g += $interval) {
13+
for ($b = 0; $b <= 256; $b += $interval) {
14+
$i = ($i + 1) % $column;
15+
$rr = $r < 0 ? 0 : ($r > 255 ? 255 : $r);
16+
$gg = $g < 0 ? 0 : ($g > 255 ? 255 : $g);
17+
$bb = $b < 0 ? 0 : ($b > 255 ? 255 : $b);
18+
$s = sprintf(' [%3d;%3d;%3d] ', $rr, $gg, $bb);
19+
Colorizer::underline([$rr, $gg, $bb])
20+
->echo($s, !$i ? PHP_EOL : '');
21+
}
22+
}
23+
}

playground/underline_256colors.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
use Macocci7\BashColorizer\Colorizer;
6+
7+
$columns = 16;
8+
for ($i = 0; $i < 256; $i++) {
9+
$s = sprintf(" %3d ", $i);
10+
$eol = ($i % $columns) === ($columns - 1) ? PHP_EOL : '';
11+
Colorizer::underline($i)->echo($s, $eol);
12+
}

0 commit comments

Comments
 (0)