Permalink
Browse files

Moving rest of the color logic out of the colors module

  • Loading branch information...
1 parent 995938d commit 0eb2d786f16f1b9c72a88f2c739e51537c3db3b8 @BjRo committed Feb 3, 2014
Showing with 11 additions and 11 deletions.
  1. +5 −5 lib/apex/format/color.ex
  2. +2 −6 lib/apex/format/utils.ex
  3. +4 −0 test/format/utils_test.exs
View
@@ -1,9 +1,9 @@
defmodule Apex.Format.Color do
- def colorize(text, data) do
- if color = color(data) do
- escape(text, color)
- else
- text
+ def colorize(text, data, options \\ []) do
+ cond do
+ options[:color] == false -> text
+ color = color(data) -> escape(text, color)
+ true -> text
end
end
View
@@ -4,12 +4,8 @@ defmodule Apex.Format.Utils do
def new_line, do: "\n"
- def colorize(str, data, options) do
- if options[:color] == false do
- str
- else
- Apex.Format.Color.colorize(str, data)
- end
+ def colorize(str, data, options \\ []) do
+ Apex.Format.Color.colorize(str, data, options)
end
def next_indent_level(options) do
@@ -25,4 +25,8 @@ defmodule Apex.Format.Utils.Test do
test "#colorize should not do anything when it's turned off" do
assert colorize("FOO", {}, color: false) == "FOO"
end
+
+ test "#colorize should color when it's asked for it" do
+ assert colorize("A", 1) == "\e[1;34mA\e[0m"
+ end
end

0 comments on commit 0eb2d78

Please sign in to comment.