Skip to content

Commit 7d4983b

Browse files
authored
Merge pull request #8 from Lynesth/patch-1
add getColourSupport()
2 parents f98c611 + 00ae900 commit 7d4983b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/UnixTerminal.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class UnixTerminal implements Terminal
3434
* @var int
3535
*/
3636
private $height;
37+
38+
/**
39+
* @var int;
40+
*/
41+
private $colourSupport;
3742

3843
/**
3944
* @var string
@@ -74,6 +79,11 @@ public function getHeight() : int
7479
return $this->height ?: $this->height = (int) exec('tput lines');
7580
}
7681

82+
public function getColourSupport() : int
83+
{
84+
return $this->colourSupport ?: $this->colourSupport = (int) exec('tput colors');
85+
}
86+
7787
private function getOriginalConfiguration() : string
7888
{
7989
return $this->originalConfiguration ?: $this->originalConfiguration = exec('stty -g');

test/UnixTerminalTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,16 @@ public function testWriteForwardsToOutput() : void
284284

285285
self::assertEquals('My awesome string', $output->fetch());
286286
}
287+
288+
public function testGetColourSupport() : void
289+
{
290+
$input = $this->createMock(InputStream::class);
291+
$output = new BufferedOutput;
292+
293+
$terminal = new UnixTerminal($input, $output);
294+
295+
// Travis terminal supports 8 colours, but just in case
296+
// in ever changes I'll add the 256 colors possibility too
297+
self::assertTrue($terminal->getColourSupport() === 8 || $terminal->getColourSupport() === 256);
298+
}
287299
}

0 commit comments

Comments
 (0)