Packages

Rainbow Inspector is a small library that allows you to specify a color of output given by inspect() function.

Current section

Files

Jump to
rainbow_inspector lib rainbow_inspector.ex
Raw

lib/rainbow_inspector.ex

defmodule RainbowInspector do
@moduledoc """
Upgrade version of IO.inspect() that allows to specify outputs colour.
"""
@allowed_colours ~w(
black
blue
cyan
green
magenta
red
white
yellow
)a
@doc """
Inspects `item` with given `font colour`.
Allowed font colours are :black, :blue, :cyan, :green, :magenta, :red, :white and :yellow.
"""
def inspect(item, font_colour)
def inspect(item, font_colour) when font_colour in @allowed_colours do
IO.puts(IO.ANSI.format([font_colour, inspect(item)]))
item
end
def inspect(item, _font_colour) do
IO.ANSI.reset()
IO.inspect(item)
end
end