Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Add support for true colors#36802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromfabpot:console-true-color
Jun 10, 2020

Conversation

@fabpot
Copy link
Member

@fabpotfabpot commentedMay 13, 2020
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#26576,Fix#19844
LicenseMIT
Doc PR-

This PR adds support for true colors in the Console component.

Instead of adding many ways to add more colors than the current "default" ones, I've opted to only add true color support via Hex CSS colors. If you have something else (RGB, HSV, ...), you need to first convert it to a CSS color. I've also decided to not support the ANSI 256 colors as most terminals support true colors nowadays.

If true colors are not supported by the terminal, we fall back to the "nearest" default color.

<fg=green;bg=blue> is now equivalent to<fg=#00ff00;bg=#00f>.

TheColor class is usable outside of the Console framework as well:

$color =newColor('black','white');echo$color->apply("foo");echo"\n";$color =newColor('red','yellow');echo$color->apply("foo");echo"\n";$color =newColor('#000000','#ffffff');echo$color->apply("foo");$color =newColor('#000','#fff', ['underscore','reverse']);echo$color->apply("bar");echo"\n";

Rainbow time!

functionrainbowColor($i) {$h = (int) ($i /43);$f = (int) ($i -43 *$h);$t = (int) ($f *255 /43);$q =255 -$t;if ($h ==0) {returnnewColor('',sprintf('#FF%02x00',$t));    }elseif ($h ==1) {returnnewColor('',sprintf('#%02xFF00',$q));    }elseif ($h ==2) {returnnewColor('',sprintf('#00FF%02x',$t));    }elseif ($h ==3) {returnnewColor('',sprintf('#00%02xFF',$q));    }elseif ($h ==4) {returnnewColor('',sprintf('#%02x00FF',$t));    }elseif ($h ==5) {returnnewColor('',sprintf('#FF00%02x',$q));    }}for ($i =0;$i <128;$i++) {echorainbowColor($i)->apply('');}echo"\n";for ($i =255;$i >=128;$i--) {echorainbowColor($i)->apply('');}echo"\n";

image

javiereguiluz, GromNaN, Guikingone, weaverryan, and noniagriconomie reacted with thumbs up emojijaviereguiluz reacted with hooray emojijaviereguiluz, wouterj, dadangnh, BadaievOleksii, and ogizanagi reacted with heart emojijaviereguiluz, sstok, and alexislefebvre reacted with rocket emoji
@fabpotfabpotforce-pushed theconsole-true-color branch 2 times, most recently from8ff5fb5 toc8b9489CompareMay 13, 2020 10:27
@nicolas-grekasnicolas-grekas added this to thenext milestoneMay 13, 2020
}

if (!isset(static::$colors[$color])) {
thrownewInvalidArgumentException(sprintf('Invalid "%s" color; expected one of (%s).',$color,implode(',',array_keys(static::$colors))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

maybe we can point out here that the user should use one of the predefined colors or an hexadecimal one ?

@stof
Copy link
Member

If you have something else (RGB, HSV, ...), you need to first convert it to a CSS color.

I guess you need to reword your description, to talk about hex colors. CSS colorsdo support RGB and HSL (and more to come)

fabpot and sstok reacted with thumbs up emojisstok reacted with laugh emoji

@fabpot
Copy link
MemberAuthor

Anyone willing to test on Windows?

*/
finalclass Color
{
privatestatic$colors = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

shoudn't these be consts instead ? (Same for$availableOptions)

@wouterj
Copy link
Member

Some tests with theColor class + the rainbow script on some windows command lines (I couldn't test the whole repository, as I haven't set-up my windows PC for development at all). As expected, no true color support, but seems like default colors work as expected.

Windows Powershell
powershell

Git Bash GUI
git bash

Command prompt
cmd

WSL
wsl

@fabpot
Copy link
MemberAuthor

Thanks@wouterj for testing on Windows.

@fabpotfabpot merged commitea956b1 intosymfony:masterJun 10, 2020
@fabpotfabpot deleted the console-true-color branchJune 10, 2020 03:08
@nicolas-grekasnicolas-grekas modified the milestones:next,5.2Oct 5, 2020
@fabpotfabpot mentioned this pull requestOct 5, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@stofstofstof requested changes

+2 more reviewers

@TaluuTaluuTaluu left review comments

@kevin-verschaevekevin-verschaevekevin-verschaeve left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.2

Development

Successfully merging this pull request may close these issues.

8 participants

@fabpot@stof@wouterj@javiereguiluz@Taluu@kevin-verschaeve@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp