File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff 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 ' );
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments