Easier terminal styling
This library is a very light abstraction over IO.ANSI that makes it easy to style text. It's heavily inspired by Node's chalk.
In your mix.exs:
defp deps do
[
{ :exchalk, "~> 1.0.2" }
]
endThen run mix deps.get.
IO.puts ExChalk.red("Hello world!")
# or
"Hello world!"
|> ExChalk.red
|> ExChalk.italic
|> ExChalk.bg_blue
|> IO.putsresetbolddimitalic(not widely supported)underlineinversehiddenstrikethrough(not widely supported)
blackredgreenyellowbluemagentacyanwhitegray
bg_blackbg_redbg_greenbg_yellowbg_bluebg_magentabg_cyanbg_white
ExChalk by default returns IO lists instead of strings. IO lists can be printed, but since they aren't strings the <> doesn't work (though interpolation does!).
If you're planning on doing a lot of concatenation this may sound annoying, but there's a good reason. IO lists are a lot more performant than strings as they require less allocation and copying.
See José's explanation in this thread for more information.
ExChalk does not support anything other than the base eight colors, which guarantees it will work on all terminals and systems. Some terminals, specifically xterm compliant ones, will support the full range of 8-bit colors. For this, the lower level IO.ANSI or the awesome Bunt can be used.
If you're on Windows, do yourself a favor and use cmder instead of cmd.exe.
MIT © Juan Soto
