Skip to content

Commit

Permalink
Update colorize method
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Dec 13, 2023
1 parent 2ff8a7d commit 2526fa5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,19 @@ public function confirm(
return $response;
}

/**
* Colorize a string for output
*
* @param string $string
* @param ?int $fg
* @param ?int $bg
* @return string
*/
public function colorize(string $string, ?int $fg = null, ?int $bg = null): string
{
return Color::colorize($string, $fg, $bg);
}

/**
* Append a string of text to the response body
*
Expand Down
9 changes: 9 additions & 0 deletions tests/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,15 @@ public function testAlertBox6()
$this->assertTrue(str_contains($result, "Hello World"));
}

public function testColor()
{
$console = new Console();
$string = $console->colorize('Hello World', Color::BOLD_BLUE, Color::RED);
$this->assertStringContainsString('[1;34m', $string);
$this->assertStringContainsString('[41m', $string);
$this->assertStringContainsString('[0m', $string);
}

public function testAppend()
{
$console = new Console();
Expand Down

0 comments on commit 2526fa5

Please sign in to comment.