27 lines
743 B
PHP
27 lines
743 B
PHP
<?php
|
|
|
|
namespace util;
|
|
|
|
class AnsiUtil {
|
|
|
|
public static function wrap(string $text,
|
|
?AnsiColor $fg = null,
|
|
?AnsiColor $bg = null,
|
|
bool $bold = false,
|
|
bool $fg_bright = false,
|
|
bool $bg_bright = false): string {
|
|
$codes = [];
|
|
if (!is_null($fg))
|
|
$codes[] = $fg->value + ($fg_bright ? 90 : 30);
|
|
if (!is_null($bg))
|
|
$codes[] = $bg->value + ($bg_bright ? 100 : 40);
|
|
if ($bold)
|
|
$codes[] = 1;
|
|
|
|
if (empty($codes))
|
|
return $text;
|
|
|
|
return "\033[".implode(';', $codes)."m".$text."\033[0m";
|
|
}
|
|
|
|
} |