diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-07-09 19:40:17 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-07-09 19:40:17 +0300 |
commit | f7bfdf58def6aadc922e1632f407d1418269a0d7 (patch) | |
tree | d7a0b2819e6a26c11d40ee0b27267ea827fbb345 /engine/ansi.php |
initial
Diffstat (limited to 'engine/ansi.php')
-rw-r--r-- | engine/ansi.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/engine/ansi.php b/engine/ansi.php new file mode 100644 index 0000000..311c837 --- /dev/null +++ b/engine/ansi.php @@ -0,0 +1,34 @@ +<?php + +namespace ansi; + +enum Color: int { + case BLACK = 0; + case RED = 1; + case GREEN = 2; + case YELLOW = 3; + case BLUE = 4; + case MAGENTA = 5; + case CYAN = 6; + case WHITE = 7; +} + +function wrap(string $text, + ?Color $fg = null, + ?Color $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"; +}
\ No newline at end of file |