Skip to content

add getColourSupport() #8

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 5 commits into from
May 5, 2018
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/UnixTerminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class UnixTerminal implements Terminal
* @var int
*/
private $height;

/**
* @var int;
*/
private $colourSupport;

/**
* @var string
Expand Down Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions test/UnixTerminalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}