Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use ANSI colors on terminals that support ANSI #38

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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