Created
July 12, 2016 17:04
-
-
Save batok/200c9e79e7540494a2780ee5957ecaa0 to your computer and use it in GitHub Desktop.
Colorear consola
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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