-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.php
executable file
·156 lines (119 loc) · 4 KB
/
sample.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env php
<?php
declare(strict_types=1);
use BeBat\ConsoleColor\Style;
use const PHP_EOL;
use const STR_PAD_LEFT;
$localPath = __DIR__ . '/vendor/autoload.php';
$installedPath = dirname(__DIR__, 2) . '/autoload.php';
if (is_file($installedPath)) {
require_once $installedPath;
} elseif (is_file($localPath)) {
require_once $localPath;
} else {
throw new RuntimeException('Could not find autoload file. Make sure to run "composer install" first.');
}
$style = new Style();
$style->force();
echo 'Styling supported: ' . ($style->supportsStyles ? 'Yes' : 'No') . PHP_EOL;
echo '256 colors supported: ' . ($style->supports256Colors ? 'Yes' : 'No') . PHP_EOL;
echo '24-bit true colors supported: ' . ($style->supportsRGBColors ? 'Yes' : 'No') . PHP_EOL;
echo PHP_EOL;
function printEnumStyleSample(string $heading, string $enum): void
{
global $style;
echo $heading . PHP_EOL;
foreach ($enum::cases() as $styleValue) {
echo ' ' . $style->apply($styleValue->name, $styleValue) . PHP_EOL;
}
echo PHP_EOL;
}
function print256ColorSample(string $heading, string $method): void
{
global $style;
echo "256 {$heading} Colors" . PHP_EOL;
for ($i = 0; $i < 256; ++$i) {
if ($i === 0 || $i < 231 && $i % 18 === 16 || 231 < $i && $i % 12 === 4) {
echo ' ';
}
echo $style->apply(
str_pad((string) $i, 4, ' ', STR_PAD_LEFT),
Style\Color256::{$method}($i),
);
if ($i === 15 || $i === 231) {
echo PHP_EOL . PHP_EOL;
}
if (15 < $i && $i < 231 && $i % 18 === 15 || $i === 243 || $i === 255) {
echo PHP_EOL;
}
}
echo PHP_EOL;
}
function printTrueColorSample(string $heading, string $method): void
{
global $style;
echo "True Color {$heading} (Abridged)" . PHP_EOL;
for ($red = 0; $red < 8; ++$red) {
for ($green = 0; $green < 8; ++$green) {
for ($blue = 0; $blue < 8; ++$blue) {
if ($blue % 8 === 0 && $green % 8 === 0) {
echo ' ';
}
echo $style->apply(
'X',
Style\ColorRGB::{$method}($red * 32, $green * 32, $blue * 32),
);
if ($blue % 8 === 7 && $green % 8 === 7) {
echo PHP_EOL;
}
}
}
}
echo PHP_EOL;
}
printEnumStyleSample('Text Styles', Style\Text::class);
printEnumStyleSample('Underline Styles', Style\Underline::class);
printEnumStyleSample('Foreground Colors', Style\Color::class);
printEnumStyleSample('Background Colors', Style\BackgroundColor::class);
print256ColorSample('Foreground', 'foreground');
print256ColorSample('Background', 'background');
echo '256 Underline Colors' . PHP_EOL;
for ($i = 0; $i < 256; ++$i) {
if ($i === 0 || $i < 231 && $i % 18 === 16 || 231 < $i && $i % 12 === 4) {
echo ' ';
}
echo $style->apply(
str_pad((string) $i, 4, ' ', STR_PAD_LEFT),
new Style\Composite(Style\Text::Underline, Style\Color256::underline($i)),
);
if ($i === 15 || $i === 231) {
echo PHP_EOL . PHP_EOL;
}
if (15 < $i && $i < 231 && $i % 18 === 15 || $i === 243 || $i === 255) {
echo PHP_EOL;
}
}
echo PHP_EOL;
printTrueColorSample('Foreground', 'foreground');
printTrueColorSample('Background', 'background');
echo 'True Color Underline (Abridged)' . PHP_EOL;
for ($red = 0; $red < 8; ++$red) {
for ($green = 0; $green < 8; ++$green) {
for ($blue = 0; $blue < 8; ++$blue) {
if ($blue % 8 === 0 && $green % 8 === 0) {
echo ' ';
}
echo $style->apply(
'X',
new Style\Composite(
Style\Text::Underline,
Style\ColorRGB::underline($red * 32, $green * 32, $blue * 32),
),
);
if ($blue % 8 === 7 && $green % 8 === 7) {
echo PHP_EOL;
}
}
}
}
echo PHP_EOL;