diff --git a/CHANGELOG.md b/CHANGELOG.md index 0129d61..de03e35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v0.1.1 + +### New features + +* Add `notice/1` and `success/1` semantic log helpers +* Add `enable_colors/0` to help enabling ANSI colors + ## v0.1.0 * Initial version extracted from xgen diff --git a/README.md b/README.md index c30d80e..0d23a19 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,10 @@ Marcus is a library for writing interactive CLIs in Elixir. Marcus provides helpers for: +* enabling ANSI colors, * printing ANSI-formatted information, +* printing notices in bright blue, +* printing success messages in brigh green, * printing information in green, * printing errors (in bright red, on `stderr`) * halting the VM with an error message and status. @@ -52,7 +55,7 @@ choose("Make a choice:", item1: "Item 1", item2: "Item 2") To use Marcus in your project, add this to your Mix dependencies: ```elixir -{:marcus, "~> 0.1.0"} +{:marcus, "~> 0.1.1"} ``` ## [Contributing](CONTRIBUTING.md) diff --git a/lib/marcus.ex b/lib/marcus.ex index caa995d..225c95f 100644 --- a/lib/marcus.ex +++ b/lib/marcus.ex @@ -6,7 +6,10 @@ defmodule Marcus do Marcus provides helpers for: + * enabling ANSI colors, * printing ANSI-formatted information, + * printing notices in bright blue, + * printing success messages in brigh green, * printing information in green, * printing errors (in bright red, on `stderr`) * halting the VM with an error message and status. @@ -52,6 +55,14 @@ defmodule Marcus do @yes ~w(y Y yes YES Yes) @no ~w(n N no NO No) + @doc """ + Enables ANSI colors. + """ + @spec enable_colors :: :ok + def enable_colors do + Application.put_env(:elixir, :ansi_enabled, true) + end + @doc """ Prints the given ANSI-formatted `message`. """ @@ -60,6 +71,22 @@ defmodule Marcus do message |> ANSI.format() |> IO.puts() end + @doc """ + Prints the given ANSI-formatted `message` in bright blue. + """ + @spec notice(ANSI.ansidata()) :: :ok + def notice(message) do + info([:blue, :bright, message]) + end + + @doc """ + Prints the given ANSI-formatted `message` in bright green. + """ + @spec success(ANSI.ansidata()) :: :ok + def success(message) do + info([:green, :bright, message]) + end + @doc """ Prints the given ANSI-formatted `message` in green. """ diff --git a/mix.exs b/mix.exs index e5f5042..9a38f05 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Marcus.MixProject do use Mix.Project - @version "0.1.0" + @version "0.1.1" @repo_url "https://github.com/ejpcmac/marcus" def project do diff --git a/test/marcus_test.exs b/test/marcus_test.exs index b46eb3c..34c3cd1 100644 --- a/test/marcus_test.exs +++ b/test/marcus_test.exs @@ -7,6 +7,13 @@ defmodule MarcusTest do alias IO.ANSI + test "enable_colors/0 enables ANSI colors" do + Application.put_env(:elixir, :ansi_enabled, false) + + assert enable_colors() == :ok + assert Application.get_env(:elixir, :ansi_enabled) == true + end + describe "info/1" do property "prints the given message" do check all message <- string(:printable) do @@ -22,6 +29,25 @@ defmodule MarcusTest do end end + describe "success/1" do + property "prints the given message in bright green" do + check all message <- string(:printable) do + assert capture_io(fn -> success(message) end) == + ANSI.green() <> + ANSI.bright() <> message <> ANSI.reset() <> "\n" + end + end + end + + describe "notice/1" do + property "prints the given message in bright blue" do + check all message <- string(:printable) do + assert capture_io(fn -> notice(message) end) == + ANSI.blue() <> ANSI.bright() <> message <> ANSI.reset() <> "\n" + end + end + end + describe "green_info/1" do property "prints the given message in green" do check all message <- string(:printable) do