DEV Community

Cover image for What I've learned today - 3 - Elixir add color to console
Luan Gomes
Luan Gomes

Posted on • Updated on

What I've learned today - 3 - Elixir add color to console

Coloring your console prints

Since Elixir 1.4.0 we have ANSI color printing option.

Ir supports also background colors.

For more information, see: https://hexdocs.pm/elixir/IO.ANSI.html

Examples

import IO.ANSI
IO.puts red <> "red" <> green <> " green" <> yellow <> " yellow" <> reset <> " normal"
IO.puts Enum.join [red, "red", green, " green", yellow, " yellow", reset, " normal"]
IO.puts IO.ANSI.format([:blue_background, "Example"])
IO.puts IO.ANSI.format([:green_background, "Example"])
Enter fullscreen mode Exit fullscreen mode

Alt Text

I appreciate everyone who has read through here, if you guys have anything to add, please leave a comment.

Discussion (0)