Don't color IEx exception if it contains ANSI (#12680)

This commit is contained in:
Vinícius Müller
2023-06-20 15:49:17 +02:00
committed by GitHub
parent 9b132a2e6d
commit 89ff2a798c
2 changed files with 30 additions and 1 deletions
+7 -1
View File
@@ -400,7 +400,13 @@ defmodule IEx.Evaluator do
[IEx.color(:eval_error, banner), pad(blame)]
_ ->
[IEx.color(:eval_error, Exception.format_banner(kind, blamed, stacktrace))]
banner = Exception.format_banner(kind, blamed, stacktrace)
if String.contains?(banner, IO.ANSI.reset()) do
[banner]
else
[IEx.color(:eval_error, banner)]
end
end
stackdata = Exception.format_stacktrace(prune_stacktrace(stacktrace))
+23
View File
@@ -19,6 +19,29 @@ defmodule IEx.InteractionTest do
assert capture_iex("1 + 2") == "3"
end
test "omits error color if exception has ansi reset character" do
enabled? = IO.ANSI.enabled?()
Application.put_env(:elixir, :ansi_enabled, true)
expected = """
** (SyntaxError) invalid syntax found on iex:1:4:
┌─ \e[31merror: \e[0miex:1:4
│
1 │ a += 2
│ \e[31m ^\e[0m
│
syntax error before: '='
"""
opts = [colors: [enabled: true]]
output = capture_iex("a += 2", opts)
refute String.starts_with?(output, IO.ANSI.red())
assert output =~ expected
Application.put_env(:elixir, :ansi_enabled, enabled?)
end
test "invalid input" do
output = capture_iex("if true do ) false end")