From 4c13083d18880e634e377eb750978531a844d502 Mon Sep 17 00:00:00 2001 From: dhoegh Date: Sat, 17 Jan 2015 19:22:15 +0100 Subject: [PATCH] Added so `!Matched` is printed in front of a type that is not matched when `have_color=false` --- base/replutil.jl | 14 +++++++++----- test/replutil.jl | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/base/replutil.jl b/base/replutil.jl index 9c378b9f19843f..80543a391232bc 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -195,13 +195,15 @@ function show_method_candidates(io::IO, ex::MethodError) # checks if the type of arg 1:i of the input intersects with the current method t_in = typeintersect(method.sig[1:i], tuple(t_i[1:j]...)) if t_in == None + if Base.have_color + print(buf, "\e[1m\e[31m::$(method.sig[i])\e[0m") + else + print(buf, "!Matched::$(method.sig[i])") + end # If there is no typeintersect then the type signature from the method is # inserted in t_i this ensures if the type at the next i matches the type # signature then there will be a type intersect t_i[i] = method.sig[i] - Base.with_output_color(:red, buf) do buf - print(buf, "::$(method.sig[i])") - end else right_matches += j==i ? 1 : 0 print(buf, "::$(method.sig[i])") @@ -221,8 +223,10 @@ function show_method_candidates(io::IO, ex::MethodError) # arguments is printed as not a match for sigtype in method.sig[length(t_i)+1:end] print(buf, ", ") - Base.with_output_color(:red, buf) do buf - print(buf, "::$(sigtype)") + if Base.have_color + print(buf, "\e[1m\e[31m::$sigtype\e[0m") + else + print(buf, "!Matched::$sigtype") end end end diff --git a/test/replutil.jl b/test/replutil.jl index 6c2d15c061d766..94d54790a2809c 100644 --- a/test/replutil.jl +++ b/test/replutil.jl @@ -10,11 +10,12 @@ method_c1(x::Float64, s::AbstractString...) = true buf = IOBuffer() Base.show_method_candidates(buf, Base.MethodError(method_c1,(1, 1, ""))) -no_color = "\nClosest candidates are:\n method_c1(::Float64, ::AbstractString...)\n" +no_color = "\nClosest candidates are:\n method_c1(!Matched::Float64, !Matched::AbstractString...)\n" test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c1(\e[1m\e[31m::Float64\e[0m, \e[1m\e[31m::AbstractString...\e[0m)\n\e[0m", no_color) +no_color = "\nClosest candidates are:\n method_c1(!Matched::Float64, ::AbstractString...)\n" Base.show_method_candidates(buf, Base.MethodError(method_c1,(1, "", ""))) test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c1(\e[1m\e[31m::Float64\e[0m, ::AbstractString...)\n\e[0m", @@ -37,5 +38,5 @@ method_c2{T<:Real}(x::T, y::T, z::T) = true Base.show_method_candidates(buf, Base.MethodError(method_c2,(1., 1., 2))) color = "\e[0m\nClosest candidates are:\n method_c2(\e[1m\e[31m::Int32\e[0m, ::Float64, ::Any...)\n method_c2(\e[1m\e[31m::Int32\e[0m, ::Any...)\n method_c2{T<:Real}(::T<:Real, ::T<:Real, \e[1m\e[31m::T<:Real\e[0m)\n ...\n\e[0m" -no_color = no_color = "\nClosest candidates are:\n method_c2(::Int32, ::Float64, ::Any...)\n method_c2(::Int32, ::Any...)\n method_c2{T<:Real}(::T<:Real, ::T<:Real, ::T<:Real)\n ...\n" +no_color = no_color = "\nClosest candidates are:\n method_c2(!Matched::Int32, ::Float64, ::Any...)\n method_c2(!Matched::Int32, ::Any...)\n method_c2{T<:Real}(::T<:Real, ::T<:Real, !Matched::T<:Real)\n ...\n" test_have_color(buf, color, no_color) \ No newline at end of file