composer require glhd/ansipants
You can instantiate a new ANSI string using the ansi()
helper, with new AnsiString()
,
or with AnsiString::make()
. All string manipulation functions can be chained, just like
the Laravel Stringable
class. Where appropriate, you can pass an additional ignore_style: true
argument into a function to make that function ignore the ANSI styles that are applied
(like color or font style).
An example:
ansi("\e[1mHello💥 \e[3mwo\e[0mrld")
->append(" 🥸🥸🥸")
->padLeft(100)
->wordwrap();
You can also create an ANSI string from any Stringable
object:
Str::of("\e[1mHello💥 \e[3mwo\e[0mrld")->ansi();
// Or
str("\e[1mHello💥 \e[3mwo\e[0mrld")->ansi();