Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ejpcmac committed Oct 15, 2018
2 parents 28cf0e4 + 56b6246 commit d35ffbe
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions lib/marcus.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
"""
Expand All @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/marcus_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d35ffbe

Please sign in to comment.