Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ composer require macocci7/bash-colorizer
->echo("Hi, there!", PHP_EOL);
```

by hex code:
```php
Colorizer::foreground('#ffcc00') // or #fc0
->echo("Hi, there!", PHP_EOL);
```

by number [0 - 255] (256 colors):
```php
Colorizer::foreground(2)
Expand All @@ -145,6 +151,12 @@ composer require macocci7/bash-colorizer
->echo("Hi, there!", PHP_EOL);
```

by hex code:
```php
Colorizer::background("#ffcc00") // or #fc0
->echo("Hi, there!", PHP_EOL);
```

by number [0 - 255] (256 colors):
```php
Colorizer::background(1)
Expand All @@ -168,6 +180,28 @@ composer require macocci7/bash-colorizer
->echo("Hi, there!", PHP_EOL);
```

- Setting underline color:

by hex code:
```php
Colorizer::underline("#ffcc00") // or #fc0
->echo("Hi, there!", PHP_EOL);
```

by number [0 - 255] (256 colors):
```php
Colorizer::underline(1)
->echo("Hi, there!", PHP_EOL);
```

by (RGB) array (24bit 16777216 colors):
```php
Colorizer::underline([255, 0, 0])
->echo("Hi, there!", PHP_EOL);
```

See more: [Available Colors](#63-available-colors)

- Returning colorized string:

As an argument of echo:
Expand Down Expand Up @@ -223,22 +257,34 @@ composer require macocci7/bash-colorizer
|`no-italic`|〇|〇|
|`no-underline`|〇|〇|
|`no-blink`|ー<br><a href="#note3">*3</a>|〇<br><a href="#note4">*4</a>|
|`proportional-spacing`|ー|ー|
|`no-reverse`|〇|〇|
|`no-conceal`|〇|〇|
|`no-strike`|〇|〇|
|`no-proportional-spacing`|ー|ー|
|`framed`|❌|❌|
|`encircled`|❌|❌|
|`overlined`|〇|〇|
|`no-framed-no-encircled`|ー<br><a href="#note3">*3</a>|ー<br><a href="#note3">*3</a>|
|`no-overlined`|〇|〇|
|`underline-color`|〇|▲<br><a href="#note5">*5</a>|

> <a id="note1"></a>
*1: No effect with `faint`<br>
> <a id="note2"></a>
*2: Not `fast` (blinks at the same rate as `blink`)<br>
> <a id="note3"></a>
*3: Unknown because `blink` has no effect<br>
*3: Unknown because the corresponding attribute has no effect<br>
> <a id="note4"></a>
*4: Also effective against `fast-blink`<br>
> <a id="note5"></a>
*5: Partially effective<br>

e.g.) on VSCode Terminal

<img src="arts/available_attributes.png" width="180" height="360" />
<img src="arts/available_attributes.png" width="220" height="515" />

See more: [Select Graphic Rendition parameters | ANSI escape code | Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code#Select_Graphic_Rendition_parameters)

### 6.3. Available Colors

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

- 256 colors [ 0 - 255 ]:
- 256 colors [ 0 - 255 ]: `foreground`/`background`/`underline`

e.g.) foreground colors on VSCode Terminal:

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

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

e.g.) underline colors on VSCode Terminal:

<img src="arts/underline_256colors.png" width="500" height="252" />

- 24bit (16777216) colors:

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

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

e.g.) underline colors on VSCode Terminal:

<img src="arts/underline_24bitcolors.png" width="500" height="410"/>

## 7. Examples

Example codes are in [playground](playground/) directory.
Expand All @@ -293,6 +347,8 @@ Example codes are in [playground](playground/) directory.
- [foreground_24bitcolors.php](playground/foreground_24bitcolors.php)
- [background_256colors.php](playground/background_256colors.php)
- [background_24bitcolors.php](playground/background_24bitcolors.php)
- [underline_256colors.php](playground/underline_256colors.php)
- [underline_24bitcolors.php](playground/underline_24bitcolors.php)
- [readable.php](playground/readable.php)

## 8. LICENSE
Expand Down
Binary file modified arts/available_attributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arts/underline_24bitcolors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arts/underline_256colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion playground/colorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$greeting = "Let's make your bash terminal full of colors!";

Colorizer::attributes(["bold"])
->echo(PHP_EOL)
->foreground("red")->echo(" B ")
->foreground("yellow")->echo("A ")
->foreground("white")->echo("S ")
Expand All @@ -19,7 +20,8 @@
->foreground("yellow")->echo("I ")
->foreground("white")->echo("Z ")
->foreground("green")->echo("E ")
->foreground("cyan")->echo("R", "\n\n")
->foreground("cyan")->echo("R", PHP_EOL)
->echo(PHP_EOL)
;
Colorizer::attributes(["reset"])
->foreground("white")->background("black")->echo($greeting, PHP_EOL)
Expand All @@ -30,4 +32,5 @@
->foreground("green")->background("cyan")->echo($greeting, PHP_EOL)
->foreground("green")->background("blue")->echo($greeting, PHP_EOL)
->foreground("green")->background("magenta")->echo($greeting, PHP_EOL)
->echo('', PHP_EOL)
;
23 changes: 23 additions & 0 deletions playground/underline_24bitcolors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Macocci7\BashColorizer\Colorizer;

$interval = 64;
$column = 5;
$i = 0;

for ($r = 0; $r <= 256; $r += $interval) {
for ($g = 0; $g <= 256; $g += $interval) {
for ($b = 0; $b <= 256; $b += $interval) {
$i = ($i + 1) % $column;
$rr = $r < 0 ? 0 : ($r > 255 ? 255 : $r);
$gg = $g < 0 ? 0 : ($g > 255 ? 255 : $g);
$bb = $b < 0 ? 0 : ($b > 255 ? 255 : $b);
$s = sprintf(' [%3d;%3d;%3d] ', $rr, $gg, $bb);
Colorizer::underline([$rr, $gg, $bb])
->echo($s, !$i ? PHP_EOL : '');
}
}
}
12 changes: 12 additions & 0 deletions playground/underline_256colors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Macocci7\BashColorizer\Colorizer;

$columns = 16;
for ($i = 0; $i < 256; $i++) {
$s = sprintf(" %3d ", $i);
$eol = ($i % $columns) === ($columns - 1) ? PHP_EOL : '';
Colorizer::underline($i)->echo($s, $eol);
}
Loading