Created
September 15, 2022 13:53
-
-
Save forsvunnet/f0677bfd4328b0e91d4b2ee3631c8078 to your computer and use it in GitHub Desktop.
Terminal colour class for php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Terminal; | |
class Color | |
{ | |
private string $reset = "\033[0m"; | |
private string $color = "\033[0;36m"; // Cyan | |
public function __construct(private readonly string $text) | |
{ | |
} | |
public function black(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;30m"; | |
return $clone; | |
} | |
public function darkGray(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;30m"; | |
return $clone; | |
} | |
public function blue(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;34m"; | |
return $clone; | |
} | |
public function lightBlue(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;34m"; | |
return $clone; | |
} | |
public function green(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;32m"; | |
return $clone; | |
} | |
public function lightGreen(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;32m"; | |
return $clone; | |
} | |
public function cyan(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;36m"; | |
return $clone; | |
} | |
public function lightCyan(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;36m"; | |
return $clone; | |
} | |
public function red(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;31m"; | |
return $clone; | |
} | |
public function lightRed(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;31m"; | |
return $clone; | |
} | |
public function purple(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;35m"; | |
return $clone; | |
} | |
public function lightPurple(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;35m"; | |
return $clone; | |
} | |
public function brown(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;33m"; | |
return $clone; | |
} | |
public function yellow(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;33m"; | |
return $clone; | |
} | |
public function lightGray(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[0;37m"; | |
return $clone; | |
} | |
public function white(): Color | |
{ | |
$clone = clone $this; | |
$clone->color = "\033[1;37m"; | |
return $clone; | |
} | |
public function __toString(): string | |
{ | |
return $this->color.$this->text.$this->reset; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment