| 
2 | 2 | 
 
  | 
3 | 3 | namespace AlecRabbit\ConsoleColour;  | 
4 | 4 | 
 
  | 
 | 5 | +use AlecRabbit\Cli\Tools\Core\TerminalStatic;  | 
5 | 6 | use AlecRabbit\Cli\Tools\Terminal;  | 
6 | 7 | use AlecRabbit\ConsoleColour\Contracts\Styles;  | 
7 | 8 | use AlecRabbit\ConsoleColour\Core\Contracts\ConsoleColorInterface;  | 
@@ -42,6 +43,20 @@ protected function setColorSupport(bool $force, bool $force256Colors): void  | 
42 | 43 |         $this->are256ColorsSupported = $this->supported && ($force256Colors || $terminal->color() >= COLOR256_TERMINAL);  | 
43 | 44 |     }  | 
44 | 45 | 
 
  | 
 | 46 | +    /**  | 
 | 47 | +     * @param null|bool|resource $stream  | 
 | 48 | +     * @param null|bool $force  | 
 | 49 | +     * @param bool $force256Colors  | 
 | 50 | +     */  | 
 | 51 | +    public function setStream($stream = null, ?bool $force = null, bool $force256Colors = false): void  | 
 | 52 | +    {  | 
 | 53 | +        if (\is_resource($stream)) {  | 
 | 54 | +            $colorSupport = TerminalStatic::colorSupport($stream);  | 
 | 55 | +            $this->supported = $force || ($colorSupport >= COLOR_TERMINAL);  | 
 | 56 | +            $this->are256ColorsSupported = $this->supported && ($force256Colors || $colorSupport >= COLOR256_TERMINAL);  | 
 | 57 | +        }  | 
 | 58 | +    }  | 
 | 59 | + | 
45 | 60 |     /** {@inheritdoc} */  | 
46 | 61 |     public function apply($styles, $text): string  | 
47 | 62 |     {  | 
@@ -163,7 +178,7 @@ protected function isValid($style): bool  | 
163 | 178 |     }  | 
164 | 179 | 
 
  | 
165 | 180 |     /**  | 
166 |  | -     * @param int|string|array $styles  | 
 | 181 | +     * @param mixed $styles  | 
167 | 182 |      * @return array  | 
168 | 183 |      */  | 
169 | 184 |     protected function refineStyles($styles): array  | 
@@ -235,7 +250,7 @@ public function addTheme($name, $styles, bool $override = false): void  | 
235 | 250 |         if (\array_key_exists($name, $this->themes) && false === $override) {  | 
236 | 251 |             throw new \RuntimeException('Theme [' . $name . '] is already set.');  | 
237 | 252 |         }  | 
238 |  | -          | 
 | 253 | + | 
239 | 254 |         $styles = $this->refineStyles($styles);  | 
240 | 255 | 
 
  | 
241 | 256 |         foreach ($styles as $style) {  | 
 | 
0 commit comments