Skip to content

Commit

Permalink
fix: merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
saade committed Nov 28, 2023
1 parent 98598b8 commit c60cc16
Showing 1 changed file with 2 additions and 188 deletions.
190 changes: 2 additions & 188 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,192 +363,6 @@ function removeDirectory($dir): void
}
}
}

$sequences = array_filter($sequences, function ($val) {
return $val !== null;
});

if (empty($sequences)) {
return $text;
}

return $this->escSequence(implode(';', $sequences)) . $text . $this->escSequence(self::RESET_STYLE);
}

/**
* @param bool $forceStyle
*/
public function setForceStyle($forceStyle)
{
$this->forceStyle = (bool) $forceStyle;
}

/**
* @return bool
*/
public function isStyleForced()
{
return $this->forceStyle;
}

/**
* @throws InvalidStyleException
* @throws \InvalidArgumentException
*/
public function setThemes(array $themes)
{
$this->themes = [];
foreach ($themes as $name => $styles) {
$this->addTheme($name, $styles);
}
}

/**
* @param string $name
* @param array|string $styles
*
* @throws \InvalidArgumentException
* @throws InvalidStyleException
*/
public function addTheme($name, $styles)
{
if (is_string($styles)) {
$styles = [$styles];
}
if (! is_array($styles)) {
throw new \InvalidArgumentException('Style must be string or array.');
}

foreach ($styles as $style) {
if (! $this->isValidStyle($style)) {
throw new InvalidStyleException($style);
}
}

$this->themes[$name] = $styles;
}

/**
* @return array
*/
public function getThemes()
{
return $this->themes;
}

/**
* @param string $name
* @return bool
*/
public function hasTheme($name)
{
return isset($this->themes[$name]);
}

/**
* @param string $name
*/
public function removeTheme($name)
{
unset($this->themes[$name]);
}

/**
* @codeCoverageIgnore
*
* @return bool
*/
public function isSupported()
{
if (DIRECTORY_SEPARATOR === '\\') {
// phpcs:ignore Generic.PHP.NoSilencedErrors,PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound
if (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT)) {
return true;
} elseif (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON') {
return true;
}

return false;
} else {
// phpcs:ignore Generic.PHP.NoSilencedErrors
return function_exists('posix_isatty') && @posix_isatty(STDOUT);
}
}

/**
* @codeCoverageIgnore
*
* @return bool
*/
public function are256ColorsSupported()
{
if (DIRECTORY_SEPARATOR === '\\') {
// phpcs:ignore Generic.PHP.NoSilencedErrors,PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound
return function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT);
} else {
return strpos(getenv('TERM'), '256color') !== false;
}
}

/**
* @return array
*/
public function getPossibleStyles()
{
return array_keys($this->styles);
}

/**
* @param string $name
* @return string[]
*/
private function themeSequence($name)
{
$sequences = [];
foreach ($this->themes[$name] as $style) {
$sequences[] = $this->styleSequence($style);
}

return $sequences;
rmdir($dir);
}

/**
* @param string $style
* @return string
*/
private function styleSequence($style)
{
if (array_key_exists($style, $this->styles)) {
return $this->styles[$style];
}

if (! $this->are256ColorsSupported()) {
return null;
}

preg_match(self::COLOR256_REGEXP, $style, $matches);

$type = $matches[1] === 'bg_' ? self::BACKGROUND : self::FOREGROUND;
$value = $matches[2];

return "$type;5;$value";
}

/**
* @param string $style
* @return bool
*/
private function isValidStyle($style)
{
return array_key_exists($style, $this->styles) || preg_match(self::COLOR256_REGEXP, $style);
}

/**
* @param string|int $value
* @return string
*/
private function escSequence($value)
{
return "\033[{$value}m";
}
}
}

0 comments on commit c60cc16

Please sign in to comment.