diff --git a/src/UnixTerminal.php b/src/UnixTerminal.php index 7df73e3..381a873 100644 --- a/src/UnixTerminal.php +++ b/src/UnixTerminal.php @@ -34,6 +34,11 @@ class UnixTerminal implements Terminal * @var int */ private $height; + + /** + * @var int; + */ + private $colourSupport; /** * @var string @@ -74,6 +79,11 @@ public function getHeight() : int return $this->height ?: $this->height = (int) exec('tput lines'); } + public function getColourSupport() : int + { + return $this->colourSupport ?: $this->colourSupport = (int) exec('tput colors'); + } + private function getOriginalConfiguration() : string { return $this->originalConfiguration ?: $this->originalConfiguration = exec('stty -g'); diff --git a/test/UnixTerminalTest.php b/test/UnixTerminalTest.php index e1443b2..7302da6 100644 --- a/test/UnixTerminalTest.php +++ b/test/UnixTerminalTest.php @@ -284,4 +284,16 @@ public function testWriteForwardsToOutput() : void self::assertEquals('My awesome string', $output->fetch()); } + + public function testGetColourSupport() : void + { + $input = $this->createMock(InputStream::class); + $output = new BufferedOutput; + + $terminal = new UnixTerminal($input, $output); + + // Travis terminal supports 8 colours, but just in case + // in ever changes I'll add the 256 colors possibility too + self::assertTrue($terminal->getColourSupport() === 8 || $terminal->getColourSupport() === 256); + } }