Skip to content

Instantly share code, notes, and snippets.

@batok
Created July 12, 2016 17:04
Show Gist options
  • Save batok/200c9e79e7540494a2780ee5957ecaa0 to your computer and use it in GitHub Desktop.
Save batok/200c9e79e7540494a2780ee5957ecaa0 to your computer and use it in GitHub Desktop.
Colorear consola
defmodule Color do
@moduledoc false
def color_reset , do: "\x1b[0m"
def color_red, do: "\x1b[31m"
def color_green, do: "\x1b[32m"
def color_yellow, do: "\x1b[33m"
@doc """
function to add color to string to be used in console apps.
Example 1 :
"hello world" |> color_me(:green) |> IO.puts
Example 2 :
"#{color_green}hello world#{color_reset}" |> IO.puts
"""
def color_me(value, atom \\ nil) do
color = case atom do
:red -> color_red
:green -> color_green
:yellow -> color_yellow
_ -> ""
end
"#{color}#{value}#{color_reset}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment