Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wujunze/php-cli-color
Browse files Browse the repository at this point in the history
  • Loading branch information
wujunze committed Jul 18, 2018
2 parents 9cd740e + fb0e656 commit 14f8f89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct()
}

// Returns colored string
public function getColoredString($string, $foreground_color = null, $background_color = null)
public function getColoredString($string, $foreground_color = null, $background_color = null, $new_line = true)
{
$colored_string = "";

Expand All @@ -84,7 +84,7 @@ public function getColoredString($string, $foreground_color = null, $background_
// Add string and end coloring
$colored_string .= $string . "\033[0m";

return $colored_string . PHP_EOL;
return $new_line ? $colored_string . PHP_EOL : $colored_string;
}

// Returns all foreground color names
Expand Down
11 changes: 11 additions & 0 deletions tests/ColorTest/CliColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ public function testColoredString()
$this->assertEquals('Testing Colors class, this is purple string on yellow background.' . PHP_EOL, $res);
}

public function testColorString()
{
$color = $this->createServer();
$res = $color->getColoredString("Testing Colors class, this is purple string on yellow background.",
"purple",
"yellow",
false);
$this->assertEquals('Testing Colors class, this is purple string on yellow background.' , $res);

}

public function testGetBackgroundColors()
{
$color = $this->createServer();
Expand Down

0 comments on commit 14f8f89

Please sign in to comment.