Skip to content

Commit

Permalink
Removed ASCII escape codes if not enabled; fixes #2634
Browse files Browse the repository at this point in the history
  • Loading branch information
ariel-anieli authored and michaelklishin committed Jan 31, 2024
1 parent b9d2e14 commit 71fe41e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/core/ansi.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,36 @@

defmodule RabbitMQ.CLI.Core.ANSI do
def bright(string) do
"#{IO.ANSI.bright()}#{string}#{IO.ANSI.reset()}"
maybe_colorize([:bright, string])
end

def red(string) do
"#{IO.ANSI.red()}#{string}#{IO.ANSI.reset()}"
maybe_colorize([:red, string])
end

def yellow(string) do
"#{IO.ANSI.yellow()}#{string}#{IO.ANSI.reset()}"
maybe_colorize([:yellow, string])
end

def magenta(string) do
"#{IO.ANSI.magenta()}#{string}#{IO.ANSI.reset()}"
maybe_colorize([:magenta, string])
end

def bright_red(string) do
"#{IO.ANSI.bright()}#{IO.ANSI.red()}#{string}#{IO.ANSI.reset()}"
maybe_colorize([:bright, :red, string])
end

def bright_yellow(string) do
"#{IO.ANSI.bright()}#{IO.ANSI.yellow()}#{string}#{IO.ANSI.reset()}"
maybe_colorize([:bright, :yellow, string])
end

def bright_magenta(string) do
"#{IO.ANSI.bright()}#{IO.ANSI.magenta()}#{string}#{IO.ANSI.reset()}"
maybe_colorize([:bright, :magenta, string])
end

defp maybe_colorize(ascii_esc_and_string) do
ascii_esc_and_string
|> IO.ANSI.format()
|> IO.chardata_to_string()
end
end

0 comments on commit 71fe41e

Please sign in to comment.