8000 [Console] Fix color support for TTY output by theofidry · Pull Request #53707 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix color support for TTY output #53707

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Console] Fix color support
  • Loading branch information
theofidry authored and chalasr committed Feb 2, 2024
commit 22efcd028b8a5129fac580ca630d466b848a218a
16 changes: 14 additions & 2 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,22 @@ protected function hasColorSupport()
return true;
}

return 'Hyper' === getenv('TERM_PROGRAM')
if ('Hyper' === getenv('TERM_PROGRAM')
|| false !== getenv('COLORTERM')
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| str_starts_with((string) getenv('TERM'), 'xterm');
) {
return true;
}

$term = (string) getenv('TERM');

if ('dumb' === $term) {
return false;
}

// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
return 1 === @preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
}

/**
Expand Down
0