8000 [Console] Remove redundant method getSaturation() · symfony/symfony@e2ab55a · GitHub
[go: up one dir, main page]

Skip to content

Commit e2ab55a

Browse files
committed
[Console] Remove redundant method getSaturation()
1 parent 670e0f3 commit e2ab55a

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/Symfony/Component/Console/Output/AnsiColorMode.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,7 @@ private function convertFromRGB(int $r, int $g, int $b): int
7878

7979
private function degradeHexColorToAnsi4(int $r, int $g, int $b): int
8080
{
81-
if (0 === round($this->getSaturation($r, $g, $b) / 50)) {
82-
return 0;
83-
}
84-
85-
return (int) ((round($b / 255) << 2) | (round($g / 255) << 1) | round($r / 255));
86-
}
87-
88-
private function getSaturation(int $r, int $g, int $b): int
89-
{
90-
$r = $r / 255;
91-
$g = $g / 255;
92-
$b = $b / 255;
93-
$v = max($r, $g, $b);
94-
95-
if (0 === $diff = $v - min($r, $g, $b)) {
96-
return 0;
97-
}
98-
99-
return (int) ((int) $diff * 100 / $v);
81+
return round($b / 255) << 2 | (round($g / 255) << 1) | round($r / 255);
10082
}
10183

10284
/**

src/Symfony/Component/Console/Tests/Output/AnsiColorModeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ public static function provideColorsConversion(): \Generator
6464
AnsiColorMode::Ansi8->name => 248,
6565
AnsiColorMode::Ansi4->name => 7,
6666
]];
67+
68+
yield ['#000000', [
69+
AnsiColorMode::Ansi8->name => 16,
70+
AnsiColorMode::Ansi4->name => 0,
71+
]];
72+
73+
yield ['#ffffff', [
74+
AnsiColorMode::Ansi8->name => 231,
75+
AnsiColorMode::Ansi4->name => 7,
76+
]];
6777
}
6878

6979
public function testColorsConversionWithoutSharp()

0 commit comments

Comments
 (0)
0