Files
elixir-koans/lib/display/colours.ex
Ahmed Ismail edf50fdf80 Add credo to the project and:
- Run mix credo --all to identify possible code optimizations
 - Resolve most of the errors generated by credo such as:
   - Numbers larger than 9999 should be written with underscores: 58_127
   - Modules should have a @moduledoc tag
   - Comparison will always return true
2023-11-10 00:57:21 +05:00

37 lines
855 B
Elixir

defmodule Display.Paint do
@moduledoc false
def red(str), do: painter().red(str)
def cyan(str), do: painter().cyan(str)
def green(str), do: painter().green(str)
def yellow(str), do: painter().yellow(str)
defp painter do
case Mix.env() do
:test -> Display.Uncoloured
_ -> Display.Colours
end
end
end
defmodule Display.Colours do
@moduledoc false
alias IO.ANSI
def red(str), do: colourize(ANSI.red(), str)
def cyan(str), do: colourize(ANSI.cyan(), str)
def green(str), do: colourize(ANSI.green(), str)
def yellow(str), do: colourize(ANSI.yellow(), str)
defp colourize(color, message) do
Enum.join([color, message, ANSI.reset()], "")
end
end
defmodule Display.Uncoloured do
@moduledoc false
def red(str), do: str
def cyan(str), do: str
def green(str), do: str
def yellow(str), do: str
end