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

Colour output only when needed #90

Closed
wants to merge 1 commit into from

Conversation

hauleth
Copy link
Contributor

@hauleth hauleth commented May 24, 2021

Close #82

Copy link
Collaborator

@GriffinMB GriffinMB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently breaks when run in --verbose mode:

** (ArgumentError) argument error
    :erlang.bit_size([:light_magenta, ":browser"])
    (sobelow 0.11.1) lib/sobelow/print.ex:217: anonymous fn/3 in Sobelow.Print.print_code/2
    (elixir 1.11.4) lib/enum.ex:1508: anonymous fn/2 in Enum.map_join/3
    (elixir 1.11.4) lib/enum.ex:3449: Enum.map_intersperse_list/3
    (elixir 1.11.4) lib/enum.ex:1508: Enum.map_join/3
    (elixir 1.11.4) lib/macro.ex:1216: Macro.call_to_string_with_args/3
    (elixir 1.11.4) lib/macro.ex:970: Macro.to_string/2
    (sobelow 0.11.1) lib/sobelow/print.ex:214: Sobelow.Print.print_code/2

@@ -2,6 +2,8 @@ defmodule Sobelow.Print do
@moduledoc false
alias Sobelow.{Finding, Parse}

defp puts(data), do: data |> IO.ANSI.format() |> IO.puts()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a flag to toggle ANSI output that defaults to true, and works something like...

defp puts(data), do: data |> IO.ANSI.format(ansi?) |> IO.puts()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can use NO_COLOR=1 mix sobelow, Elixir support that environment variable OOtB since 1.10. For earlier versions it can be done by ERL_FLAGS="-elixir ansi_enabled false" mix sobelow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that, as-is, output isn't colored by default when Sobelow is installed as an escript.

@hauleth hauleth force-pushed the ft/colour-only-when-needed branch from e1cc229 to 7e897ca Compare May 25, 2021 07:54
@hauleth
Copy link
Contributor Author

hauleth commented May 25, 2021

Fixed that error.

@houllette
Copy link
Contributor

@hauleth I know it's been some time since this MR, but were you interested in getting this over the finish line?

From what I can tell, the last bit of work for this is the flag to toggle the ANSI output that Griffin first mentioned.

@houllette houllette closed this Jan 3, 2024
@houllette
Copy link
Contributor

Closing due to staleness - happy to reopen later / fold the changes into a new PR if someone stumbles upon this and desires this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Colour the output only if IO.ANSI.enabled?() == true
3 participants