-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
xterm-colors.php
71 lines (58 loc) · 1.57 KB
/
xterm-colors.php
1
2
3
4
5
6
7
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php declare(strict_types=1);
use AlecRabbit\ConsoleColour\ConsoleColor;
const CELL_WIDTH = 7;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/data2.php';
$c = new ConsoleColor();
echo PHP_EOL;
foreach ($colorArray2 as $num => $row) {
row($row, $c);
row($row, $c, true);
row($row, $c);
if (0 === ($num + 1) % 6) {
echo PHP_EOL;
}
}
foreach ($greyScale2 as $num => $row) {
row($row, $c, false, true);
row($row, $c, true, true);
row($row, $c, false, true);
}
echo PHP_EOL;
foreach ($xterm2 as $num => $row) {
row($row, $c, false, true);
row($row, $c, true, true);
row($row, $c, false, true);
}
echo PHP_EOL;
function row($row, ConsoleColor $c, $num = false, $bw = false)
{
foreach ($row as $index => $color) {
$textColor = textColor($bw, $color, $index);
$text =
$num ?
str_pad($color, CELL_WIDTH, ' ', STR_PAD_BOTH) :
str_repeat(' ', CELL_WIDTH);
echo $c->apply([$textColor, 'bg_color_' . $color], $text);
}
echo PHP_EOL;
}
function textColor($bw, $color, $index): string
{
$i = (int)$color;
if ($bw) {
if ($i > 243) {
$textColor = 'color_238';
} elseif ($i >= 7 && $i <= 15 && $i !== 8) {
$textColor = 'color_234';
} else {
$textColor = 'color_252';
}
} else {
$textColor = ($index >= 3 && $index <= 8) ? 'color_238' : 'color_252';
if ($i >= 160 && $i <= 231) {
$textColor = 'color_238';
}
}
return $textColor;
}