From b4e01c3ab5dcefab2ebd74b0251e66d30a7efe90 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Cugnet Date: Mon, 15 Oct 2018 00:53:41 +0200 Subject: [PATCH 1/6] Bump the version to 0.1.1-dev --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index e5f5042..859ad88 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-dev" @repo_url "https://github.com/ejpcmac/marcus" def project do From 17074ac9f42f9d12ab262e87a0e810973aee50b2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Cugnet Date: Mon, 15 Oct 2018 13:12:11 +0200 Subject: [PATCH 2/6] Add notice/1 and success/1 semantic log helpers --- lib/marcus.ex | 16 ++++++++++++++++ test/marcus_test.exs | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/marcus.ex b/lib/marcus.ex index caa995d..c3af4ad 100644 --- a/lib/marcus.ex +++ b/lib/marcus.ex @@ -60,6 +60,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/test/marcus_test.exs b/test/marcus_test.exs index b46eb3c..785fa34 100644 --- a/test/marcus_test.exs +++ b/test/marcus_test.exs @@ -22,6 +22,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 From 828caca7097d8bee4851003bce90271c94615d9f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Cugnet Date: Mon, 15 Oct 2018 13:18:14 +0200 Subject: [PATCH 3/6] Add enable_colors/0 to enable ANSI colors on demand --- lib/marcus.ex | 8 ++++++++ test/marcus_test.exs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/lib/marcus.ex b/lib/marcus.ex index c3af4ad..ff5277d 100644 --- a/lib/marcus.ex +++ b/lib/marcus.ex @@ -52,6 +52,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`. """ diff --git a/test/marcus_test.exs b/test/marcus_test.exs index 785fa34..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 From 652fed00680f5a1b9147e92123c8a93496b5a396 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Cugnet Date: Mon, 15 Oct 2018 13:21:38 +0200 Subject: [PATCH 4/6] Update the documentation --- README.md | 3 +++ lib/marcus.ex | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index c30d80e..ebac1a6 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. diff --git a/lib/marcus.ex b/lib/marcus.ex index ff5277d..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. From 427cc695ecd11d266de455091dccf681ccc2e0db Mon Sep 17 00:00:00 2001 From: Jean-Philippe Cugnet Date: Mon, 15 Oct 2018 13:25:38 +0200 Subject: [PATCH 5/6] Bump the version to 0.1.1 --- README.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ebac1a6..0d23a19 100644 --- a/README.md +++ b/README.md @@ -55,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/mix.exs b/mix.exs index 859ad88..9a38f05 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Marcus.MixProject do use Mix.Project - @version "0.1.1-dev" + @version "0.1.1" @repo_url "https://github.com/ejpcmac/marcus" def project do From 56b62464546d782cadd9ea51d80541b2c6dd03d4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Cugnet Date: Mon, 15 Oct 2018 13:27:17 +0200 Subject: [PATCH 6/6] Update the changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) 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