Skip to content

Commit

Permalink
Merge pull request #38 from axelson/handle-non-ansi
Browse files Browse the repository at this point in the history
Only use ANSI colors on terminals that support ANSI
  • Loading branch information
axelson authored Jun 10, 2020
2 parents c1b7cdc + da4c2d9 commit c5c27b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Improvements:
* Make logging configurable and make logging (optionally) not overwrite the IEx prompt [#32](https://github.com/falood/exsync/pull/32)
* Ensure that compilation errors are displayed in the console [#33](https://github.com/falood/exsync/pull/33)
* Add a supervision hierarchy [#35](https://github.com/falood/exsync/pull/35)
* Handle terminals that don't support ANSI colors [#38](https://github.com/falood/exsync/pull/38)

Bug fixes:
* Fix log when there are no configured group leaders [#36](https://github.com/falood/exsync/pull/36)
Expand Down
8 changes: 6 additions & 2 deletions lib/exsync/logger/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ defmodule ExSync.Logger.Server do
end

defp color_message(message, level) do
color = color(level)
[IO.ANSI.format_fragment(color, true), message | IO.ANSI.reset()]
if IO.ANSI.enabled?() do
color = color(level)
[IO.ANSI.format_fragment(color, true), message | IO.ANSI.reset()]
else
message
end
end

defp color(:debug), do: :cyan
Expand Down

0 comments on commit c5c27b7

Please sign in to comment.