Skip to content

Commit 9ca59c3

Browse files
committed
Revert "feature #43094 [Console] Add support of RGB functional notation (alexandre-daubois)"
This reverts commit eb324a1a86d30d0b858a936f40199d4c1968916b, reversing changes made to 310f2301d2a7917e99a72ddcdb88f40e3bde9521.
1 parent d386ddb commit 9ca59c3

File tree

3 files changed

+0
-58
lines changed

3 files changed

+0
-58
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ CHANGELOG
66

77
* Add `TesterTrait::assertCommandIsSuccessful()` to test command
88
* Deprecate `HelperSet::setCommand()` and `getCommand()` without replacement
9-
* Add `rgb(r, g, b)` notation support for output colors
109

1110
5.3
1211
---

Color.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ final class Color
4949
'conceal' => ['set' => 8, 'unset' => 28],
5050
];
5151

52-
private const RGB_FUNCTIONAL_NOTATION_REGEX = '/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/';
53-
5452
private $foreground;
5553
private $background;
5654
private $options = [];
@@ -118,10 +116,6 @@ private function parseColor(string $color, bool $background = false): string
118116
return '';
119117
}
120118

121-
if (str_starts_with($color, 'rgb(')) {
122-
$color = $this->rgbToHex($color);
123-
}
124-
125119
if ('#' === $color[0]) {
126120
$color = substr($color, 1);
127121

@@ -183,23 +177,4 @@ private function getSaturation(int $r, int $g, int $b): int
183177

184178
return (int) $diff * 100 / $v;
185179
}
186-
187-
private function rgbToHex(string $color): string
188-
{
189-
if (!preg_match(self::RGB_FUNCTIONAL_NOTATION_REGEX, $color, $matches)) {
190-
throw new InvalidArgumentException(sprintf('Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "%s".', $color));
191-
}
192-
193-
$rgb = \array_slice($matches, 1);
194-
195-
$hexString = array_map(function ($element) {
196-
if ($element > 255) {
197-
throw new InvalidArgumentException(sprintf('Invalid color component; value should be between 0 and 255, got %d.', $element));
198-
}
199-
200-
return str_pad(dechex((int) $element), 2, '0', \STR_PAD_LEFT);
201-
}, $rgb);
202-
203-
return '#'.implode('', $hexString);
204-
}
205180
}

Tests/ColorTest.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Color;
16-
use Symfony\Component\Console\Exception\InvalidArgumentException;
1716

1817
class ColorTest extends TestCase
1918
{
@@ -43,9 +42,6 @@ public function testTrueColors()
4342

4443
$color = new Color('#ffffff', '#000000');
4544
$this->assertSame("\033[38;2;255;255;255;48;2;0;0;0m \033[39;49m", $color->apply(' '));
46-
47-
$color = new Color('rgb(255, 255, 255)', 'rgb(0, 0, 0)');
48-
$this->assertSame("\033[38;2;255;255;255;48;2;0;0;0m \033[39;49m", $color->apply(' '));
4945
}
5046

5147
public function testDegradedTrueColors()
@@ -63,32 +59,4 @@ public function testDegradedTrueColors()
6359
putenv('COLORTERM='.$colorterm);
6460
}
6561
}
66-
67-
/**
68-
* @dataProvider provideMalformedRgbStrings
69-
*/
70-
public function testMalformedRgbString(string $color, string $exceptionMessage)
71-
{
72-
$this->expectException(InvalidArgumentException::class);
73-
$this->expectExceptionMessage($exceptionMessage);
74-
75-
new Color($color);
76-
}
77-
78-
public function provideMalformedRgbStrings(): \Generator
79-
{
80-
yield ['rgb()', 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb()".'];
81-
82-
yield ['rgb(0, 0)', 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(0, 0)".'];
83-
84-
yield ['rgb(0, 0, 0, 0)', 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(0, 0, 0, 0)".'];
85-
86-
yield ['rgb(-1, 0, 0)', 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(-1, 0, 0)".'];
87-
88-
yield ['rgb(invalid, 0, 0)', 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(invalid, 0, 0)".'];
89-
90-
yield ['rgb(256, 0, 0)', 'Invalid color component; value should be between 0 and 255, got 256.'];
91-
92-
yield ['rgb(0, 0, 0', 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(0, 0, 0".'];
93-
}
9462
}

0 commit comments

Comments
 (0)