Don't color IEx exception if it contains ANSI (#12680)
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user