diff --git a/base/errorshow.jl b/base/errorshow.jl index 2baf5d2471315..e84d8b0648c3a 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -568,6 +568,12 @@ stacktrace_contract_userdir()::Bool = tryparse(Bool, get(ENV, "JULIA_STACKTRACE_CONTRACT_HOMEDIR", "true")) === true stacktrace_linebreaks()::Bool = tryparse(Bool, get(ENV, "JULIA_STACKTRACE_LINEBREAKS", "false")) === true +stacktrace_color_lines()::Bool = + tryparse(Bool, get(ENV, "JULIA_STACKTRACE_COLOR_LINES", "true")) === true +stacktrace_color_modules()::Bool = + tryparse(Bool, get(ENV, "JULIA_STACKTRACE_COLOR_MODULES", "true")) === true + +stacktrace_line_color() = stacktrace_color_lines() ? :light_black : :normal function show_full_backtrace(io::IO, trace::Vector; print_linebreaks::Bool) num_frames = length(trace) @@ -660,7 +666,8 @@ function show_reduced_backtrace(io::IO, t::Vector) popfirst!(repeated_cycle) printstyled(io, "--- the last ", cycle_length, " lines are repeated ", - repetitions, " more time", repetitions>1 ? "s" : "", " ---", color = :light_black) + repetitions, " more time", repetitions>1 ? "s" : "", " ---", + color=stacktrace_line_color()) if i < length(displayed_stackframes) println(io) stacktrace_linebreaks() && println(io) @@ -677,7 +684,7 @@ end # from `modulecolorcycler`. function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, modulecolordict, modulecolorcycler) m = Base.parentmodule(frame) - if m !== nothing + if m !== nothing && stacktrace_color_modules() while parentmodule(m) !== m pm = parentmodule(m) pm == Main && break @@ -715,12 +722,12 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, m StackTraces.show_spec_linfo(IOContext(io, :backtrace=>true), frame) if n > 1 - printstyled(io, " (repeats $n times)"; color=:light_black) + printstyled(io, " (repeats $n times)"; color=stacktrace_line_color()) end println(io) # @ - printstyled(io, " " ^ (digit_align_width + 2) * "@ ", color = :light_black) + printstyled(io, " " ^ (digit_align_width + 2) * "@ "; color=stacktrace_line_color()) # module if modul !== nothing @@ -732,14 +739,15 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, m pathparts = splitpath(file) folderparts = pathparts[1:end-1] if !isempty(folderparts) - printstyled(io, joinpath(folderparts...) * (Sys.iswindows() ? "\\" : "/"), color = :light_black) + printstyled(io, joinpath(folderparts...) * (Sys.iswindows() ? "\\" : "/"); + color=stacktrace_line_color()) end # filename, separator, line # use escape codes for formatting, printstyled can't do underlined and color # codes are bright black (90) and underlined (4) function print_underlined(io::IO, s...) - colored = get(io, :color, false)::Bool + colored = get(io, :color, false)::Bool && stacktrace_hascolor() start_s = colored ? "\033[90;4m" : "" end_s = colored ? "\033[0m" : "" print(io, start_s, s..., end_s) @@ -747,7 +755,7 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, digit_align_width, m print_underlined(io, pathparts[end], ":", line) # inlined - printstyled(io, inlined ? " [inlined]" : "", color = :light_black) + printstyled(io, inlined ? " [inlined]" : ""; color=stacktrace_line_color()) end diff --git a/base/show.jl b/base/show.jl index 278a5c96df615..54f1e5afd33ea 100644 --- a/base/show.jl +++ b/base/show.jl @@ -2274,7 +2274,7 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type; first || print(io, ", ") first = false if show_argnames - print_within_stacktrace(io, argnames[i]; color=:light_black) + print_within_stacktrace(io, argnames[i]; color=stacktrace_line_color()) end print(io, "::") print_type_stacktrace(env_io, sig[i]) @@ -2285,7 +2285,7 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type; for (k, t) in kwargs first || print(io, ", ") first = false - print_within_stacktrace(io, k; color=:light_black) + print_within_stacktrace(io, k; color=stacktrace_line_color()) print(io, "::") print_type_stacktrace(io, t) end @@ -2302,7 +2302,7 @@ function print_type_stacktrace(io, type; color=:normal) printstyled(io, str; color=color) else printstyled(io, str[1:prevind(str,i)]; color=color) - printstyled(io, str[i:end]; color=:light_black) + printstyled(io, str[i:end]; color=stacktrace_line_color()) end end