From 987759429a17085a5f605f655873b6a24639d351 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 26 Jan 2018 18:41:05 -0800 Subject: [PATCH] Deprecate print_with_color (#25522) This deprecates print_with_color in favor of printstyled, which accepts the color as a keyword argument. --- DISTRIBUTING.md | 2 +- base/client.jl | 2 +- base/deprecated.jl | 10 +++--- base/docs/utils.jl | 10 +++--- base/exports.jl | 2 +- base/markdown/IPython/IPython.jl | 4 +-- base/markdown/render/terminal/render.jl | 12 +++---- base/pkg/entry.jl | 6 ++-- base/precompile.jl | 2 -- base/show.jl | 12 +++---- base/stacktraces.jl | 5 ++- base/util.jl | 16 ++++----- doc/src/base/io-network.md | 2 +- stdlib/Logging/src/ConsoleLogger.jl | 10 +++--- stdlib/REPL/src/precompile.jl | 3 +- stdlib/Test/src/Test.jl | 44 ++++++++++++------------- stdlib/Test/src/logging.jl | 6 ++-- test/misc.jl | 14 ++++---- test/runtests.jl | 16 ++++----- 19 files changed, 88 insertions(+), 90 deletions(-) diff --git a/DISTRIBUTING.md b/DISTRIBUTING.md index c30fc671cb10f..a159188e8f32c 100644 --- a/DISTRIBUTING.md +++ b/DISTRIBUTING.md @@ -371,7 +371,7 @@ for result in eachrow(results) else continue end - print_with_color(color, result[:package], ": Release ", a, " -> Backport ", b, "\n") + printstyled(result[:package], ": Release ", a, " -> Backport ", b, "\n", color=color) end ``` diff --git a/base/client.jl b/base/client.jl index 3d34c514d4a4d..ec75882521ba5 100644 --- a/base/client.jl +++ b/base/client.jl @@ -156,7 +156,7 @@ function display_error(io::IO, er, bt) io = redirect(io, log_error_to, st[1]) end end - print_with_color(Base.error_color(), io, "ERROR: "; bold = true) + printstyled(io, "ERROR: "; bold=true, color=Base.error_color()) # remove REPL-related frames from interactive printing eval_ind = findlast(addr->ip_matches_func(addr, :eval), bt) if eval_ind !== nothing diff --git a/base/deprecated.jl b/base/deprecated.jl index 0b108ede155e9..badec0251adab 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1023,8 +1023,8 @@ function info(io::IO, msg...; prefix="INFO: ") depwarn("`info()` is deprecated, use `@info` instead.", :info) buf = IOBuffer() iob = redirect(IOContext(buf, io), log_info_to, :info) - print_with_color(info_color(), iob, prefix; bold = true) - println_with_color(info_color(), iob, chomp(string(msg...))) + printstyled(iob, prefix; bold=true, color=info_color()) + printstyled(iob, chomp(string(msg...)), '\n', color=info_color()) print(io, String(take!(buf))) return end @@ -1061,8 +1061,8 @@ function warn(io::IO, msg...; end buf = IOBuffer() iob = redirect(IOContext(buf, io), log_warn_to, :warn) - print_with_color(warn_color(), iob, prefix; bold = true) - print_with_color(warn_color(), iob, str) + printstyled(iob, prefix; bold=true, color=warn_color()) + printstyled(iob, str, color=warn_color()) if bt !== nothing show_backtrace(iob, bt) end @@ -1410,6 +1410,8 @@ end @deprecate PipeBuffer(data, maxsize) PipeBuffer(data, maxsize = maxsize) @deprecate unsafe_wrap(T, pointer, dims, own) unsafe_wrap(T, pointer, dims, own = own) +@deprecate print_with_color(color, args...; kwargs...) printstyled(args...; kwargs..., color=color) + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/base/docs/utils.jl b/base/docs/utils.jl index 0ae186f5ea1d9..2b24abff73c5a 100644 --- a/base/docs/utils.jl +++ b/base/docs/utils.jl @@ -144,7 +144,7 @@ repl_search(s) = repl_search(STDOUT, s) function repl_corrections(io::IO, s) print(io, "Couldn't find ") - print_with_color(:cyan, io, s, '\n') + printstyled(io, s, '\n', color=:cyan) print_correction(io, s) end repl_corrections(s) = repl_corrections(STDOUT, s) @@ -163,13 +163,13 @@ function repl_latex(io::IO, s::String) latex = symbol_latex(s) if !isempty(latex) print(io, "\"") - print_with_color(:cyan, io, s) + printstyled(io, s, color=:cyan) print(io, "\" can be typed by ") - print_with_color(:cyan, io, latex, "") + printstyled(io, latex, "", color=:cyan) println(io, '\n') elseif any(c -> haskey(symbols_latex, string(c)), s) print(io, "\"") - print_with_color(:cyan, io, s) + printstyled(io, s, color=:cyan) print(io, "\" can be typed by ") with_output_color(:cyan, io) do io for c in s @@ -310,7 +310,7 @@ function printmatch(io::IO, word, match) is, _ = bestmatch(word, match) for (i, char) = enumerate(match) if i in is - print_with_color(:bold, io, char) + printstyled(io, char, bold=true) else print(io, char) end diff --git a/base/exports.jl b/base/exports.jl index 714ace76f8c1d..99090131df592 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -616,8 +616,8 @@ export prevind, print, print_shortest, - print_with_color, println, + printstyled, repeat, replace, replace!, diff --git a/base/markdown/IPython/IPython.jl b/base/markdown/IPython/IPython.jl index 51d30beb3424d..081f749d8cf46 100644 --- a/base/markdown/IPython/IPython.jl +++ b/base/markdown/IPython/IPython.jl @@ -31,5 +31,5 @@ latex(io::IO, tex::LaTeX) = latexinline(io::IO, tex::LaTeX) = print(io, '$', tex.formula, '$') -term(io::IO, tex::LaTeX, cols) = print_with_color(:magenta, io, tex.formula, '\n') -terminline(io::IO, tex::LaTeX) = print_with_color(:magenta, io, tex.formula) +term(io::IO, tex::LaTeX, cols) = printstyled(io, tex.formula, '\n', color=:magenta) +terminline(io::IO, tex::LaTeX) = printstyled(io, tex.formula, color=:magenta) diff --git a/base/markdown/render/terminal/render.jl b/base/markdown/render/terminal/render.jl index bd288b009c969..633935a9ff6f4 100644 --- a/base/markdown/render/terminal/render.jl +++ b/base/markdown/render/terminal/render.jl @@ -41,19 +41,19 @@ function term(io::IO, md::Admonition, columns) elseif lowercase(md.title) == "tip" col = :green end - print_with_color(col, io, " "^margin, "│ "; bold = true) - print_with_color(col, io, isempty(md.title) ? md.category : md.title; bold = true) - print_with_color(col, io, "\n", " "^margin, "│", "\n"; bold = true) + printstyled(io, " "^margin, "│ "; color=col, bold=true) + printstyled(io, isempty(md.title) ? md.category : md.title; color=col, bold=true) + printstyled(io, "\n", " "^margin, "│", "\n"; color=col, bold=true) s = sprint(term, md.content, columns - 10; context=io) for line in split(rstrip(s), "\n") - print_with_color(col, io, " "^margin, "│"; bold = true) + printstyled(io, " "^margin, "│"; color=col, bold=true) println(io, line) end end function term(io::IO, f::Footnote, columns) print(io, " "^margin, "│ ") - print_with_color(:bold, io, "[^$(f.id)]") + printstyled(io, "[^$(f.id)]", bold=true) println(io, "\n", " "^margin, "│") s = sprint(term, f.text, columns - 10; context=io) for line in split(rstrip(s), "\n") @@ -153,7 +153,7 @@ function terminline(io::IO, md::Link) end function terminline(io::IO, code::Code) - print_with_color(:cyan, io, code.code) + printstyled(io, code.code, color=:cyan) end terminline(io::IO, x) = show(io, MIME"text/plain"(), x) diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 66d6e99683305..8ca12aef86c55 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -182,12 +182,12 @@ function status(io::IO, pkg::AbstractString, ver::VersionNumber, fix::Bool) LibGit2.isdirty(prepo) && push!(attrs,"dirty") isempty(attrs) || print(io, " (",join(attrs,", "),")") catch err - print_with_color(Base.error_color(), io, " broken-repo (unregistered)") + printstyled(io, " broken-repo (unregistered)", color=Base.error_color()) finally close(prepo) end else - print_with_color(Base.warn_color(), io, "non-repo (unregistered)") + printstyled(io, "non-repo (unregistered)", color=Base.warn_color()) end println(io) end @@ -745,7 +745,7 @@ struct PkgTestError <: Exception end function Base.showerror(io::IO, ex::PkgTestError, bt; backtrace=true) - print_with_color(Base.error_color(), io, ex.msg) + printstyled(io, ex.msg, color=Base.error_color()) end function test(pkgs::Vector{AbstractString}; coverage::Bool=false) diff --git a/base/precompile.jl b/base/precompile.jl index 2fe437bde7a6f..8a0e3fc9294d4 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -1107,7 +1107,6 @@ precompile(Tuple{typeof(Base.uvfinalize), Base.PipeEndpoint}) precompile(Tuple{typeof(Base.uvfinalize), Base.Process}) precompile(Tuple{getfield(Base.Filesystem, Symbol("#kw##rm")), Array{Any, 1}, typeof(Base.Filesystem.rm), String}) precompile(Tuple{getfield(Base, Symbol("#kw##info")), Array{Any, 1}, typeof(Base.info), Base.IOStream, String}) -precompile(Tuple{getfield(Base, Symbol("#kw##print_with_color")), Array{Any, 1}, typeof(Base.print_with_color), Symbol, Base.IOStream, String}) precompile(Tuple{getfield(Base, Symbol("#kw##readbytes!")), Array{Any, 1}, typeof(Base.readbytes!), Base.IOStream, Array{UInt8, 1}, Int32}) precompile(Tuple{getfield(Base, Symbol("#kw##spawn")), Array{Any, 1}, typeof(Base.spawn), Base.Cmd, Tuple{Base.Pipe, Base.TTY, Base.IOStream}}) precompile(Tuple{getfield(Base, Symbol("#kw##systemerror")), Array{Any, 1}, typeof(Base.systemerror), Symbol, Bool}) @@ -1175,7 +1174,6 @@ precompile(Tuple{typeof(Base.precompilableerror), Base.LoadError, Bool}) precompile(Tuple{typeof(Base.precompilableerror), Base.PrecompilableError, Bool}) precompile(Tuple{typeof(Base.__precompile__)}) precompile(Tuple{typeof(Base.__precompile__), Bool}) -precompile(Tuple{typeof(Base.println_with_color), Symbol, Base.IOStream, Base.SubString{String}}) precompile(Tuple{typeof(Base.push!), Array{Tuple{String, Float64}, 1}, Tuple{String, Float64}}) precompile(Tuple{typeof(Base.put!), Base.Channel{Any}, Tuple{Nothing, Nothing}}) precompile(Tuple{typeof(Base.put_buffered), Base.Channel{Any}, Tuple{Nothing, Nothing}}) diff --git a/base/show.jl b/base/show.jl index f4178f3242756..651850d0bb9dd 100644 --- a/base/show.jl +++ b/base/show.jl @@ -233,12 +233,12 @@ The following properties are in common use: ```jldoctest julia> io = IOBuffer(); -julia> print_with_color(:red, IOContext(io, :color => true), "string") +julia> printstyled(IOContext(io, :color => true), "string", color=:red) julia> String(take!(io)) "\e[31mstring\e[39m" -julia> print_with_color(:red, io, "string") +julia> printstyled(io, "string", color=:red) julia> String(take!(io)) "string" @@ -907,7 +907,7 @@ end is_expected_union(u::Union) = u.a == Nothing || u.b == Nothing || u.a == Missing || u.b == Missing emphasize(io, str::AbstractString, col = Base.error_color()) = get(io, :color, false) ? - print_with_color(col, io, str; bold = true) : + printstyled(io, str; color=col, bold=true) : print(io, uppercase(str)) show_linenumber(io::IO, line) = print(io, "#= line ", line, " =#") @@ -1509,7 +1509,7 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type) # print a method signature tuple for a lambda definition color = get(io, :color, false) && get(io, :backtrace, false) ? stackframe_function_color() : :nothing if sig === Tuple - Base.print_with_color(color, io, name, "(...)") + Base.printstyled(io, name, "(...)", color=color) return end sig = unwrap_unionall(sig).parameters @@ -1529,13 +1529,13 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type) end first = true print_style = get(io, :color, false) && get(io, :backtrace, false) ? :bold : :nothing - print_with_color(print_style, io, "(") + printstyled(io, "(", color=print_style) for i = 2:length(sig) # fixme (iter): `eachindex` with offset? first || print(io, ", ") first = false print(io, "::", sig[i]) end - print_with_color(print_style, io, ")") + printstyled(io, ")", color=print_style) nothing end diff --git a/base/stacktraces.jl b/base/stacktraces.jl index 21bb5845d0a30..b699a60ed0e86 100644 --- a/base/stacktraces.jl +++ b/base/stacktraces.jl @@ -274,7 +274,10 @@ function show_spec_linfo(io::IO, frame::StackFrame) elseif frame.func === top_level_scope_sym print(io, "top-level scope") else - print_with_color(get(io, :color, false) && get(io, :backtrace, false) ? Base.stackframe_function_color() : :nothing, io, string(frame.func)) + color = get(io, :color, false) && get(io, :backtrace, false) ? + Base.stackframe_function_color() : + :nothing + printstyled(io, string(frame.func), color=color) end elseif frame.linfo isa Core.MethodInstance if isa(frame.linfo.def, Method) diff --git a/base/util.jl b/base/util.jl index e28d29d10e98f..36eb119d5e816 100644 --- a/base/util.jl +++ b/base/util.jl @@ -344,22 +344,18 @@ function with_output_color(f::Function, color::Union{Int, Symbol}, io::IO, args. end """ - print_with_color(color::Union{Symbol, Int}, [io], xs...; bold::Bool = false) + printstyled([io], xs...; bold::Bool=false, color::Union{Symbol,Int}=:normal) -Print `xs` in a color specified as a symbol. +Print `xs` in a color specified as a symbol or integer, optionally in bold. `color` may take any of the values $(Base.available_text_colors_docstring) or an integer between 0 and 255 inclusive. Note that not all terminals support 256 colors. If the keyword `bold` is given as `true`, the result will be printed in bold. """ -print_with_color(color::Union{Int, Symbol}, io::IO, msg...; bold::Bool = false) = - with_output_color(print, color, io, msg...; bold = bold) -print_with_color(color::Union{Int, Symbol}, msg...; bold::Bool = false) = - print_with_color(color, STDOUT, msg...; bold = bold) -println_with_color(color::Union{Int, Symbol}, io::IO, msg...; bold::Bool = false) = - with_output_color(println, color, io, msg...; bold = bold) -println_with_color(color::Union{Int, Symbol}, msg...; bold::Bool = false) = - println_with_color(color, STDOUT, msg...; bold = bold) +printstyled(io::IO, msg...; bold::Bool=false, color::Union{Int,Symbol}=:normal) = + with_output_color(print, color, io, msg...; bold=bold) +printstyled(msg...; bold::Bool=false, color::Union{Int,Symbol}=:normal) = + printstyled(STDOUT, msg...; bold=bold, color=color) function julia_cmd(julia=joinpath(Sys.BINDIR, julia_exename())) opts = JLOptions() diff --git a/doc/src/base/io-network.md b/doc/src/base/io-network.md index 91475df275d53..1816f7b321a6e 100644 --- a/doc/src/base/io-network.md +++ b/doc/src/base/io-network.md @@ -59,7 +59,7 @@ Base.showcompact Base.summary Base.print Base.println -Base.print_with_color +Base.printstyled Base.sprint Base.showerror Base.dump diff --git a/stdlib/Logging/src/ConsoleLogger.jl b/stdlib/Logging/src/ConsoleLogger.jl index 790e20808179f..5030852bffbca 100644 --- a/stdlib/Logging/src/ConsoleLogger.jl +++ b/stdlib/Logging/src/ConsoleLogger.jl @@ -13,7 +13,7 @@ Message formatting can be controlled by setting keyword arguments: * `meta_formatter` is a function which takes the log event metadata `(level, _module, group, id, file, line)` and returns a color (as would be - passed to print_with_color), prefix and suffix for the log message. The + passed to printstyled), prefix and suffix for the log message. The default is to prefix with the log level and a suffix containing the module, file and line location. * `show_limited` limits the printing of large data structures to something @@ -126,7 +126,7 @@ function handle_message(logger::ConsoleLogger, level, message, _module, group, i nonpadwidth = 2 + (isempty(prefix) || length(msglines) > 1 ? 0 : length(prefix)+1) + msglines[end].indent + termlength(msglines[end].msg) + (isempty(suffix) ? 0 : length(suffix)+minsuffixpad) - justify_width = min(logger.right_justify, dsize[2]) + justify_width = min(logger.right_justify, dsize[2]) if nonpadwidth > justify_width && !isempty(suffix) push!(msglines, (indent=0,msg=SubString(""))) minsuffixpad = 0 @@ -137,15 +137,15 @@ function handle_message(logger::ConsoleLogger, level, message, _module, group, i i == 1 ? "┌ " : i < length(msglines) ? "│ " : "└ " - print_with_color(color, iob, boxstr, bold=true) + printstyled(iob, boxstr, bold=true, color=color) if i == 1 && !isempty(prefix) - print_with_color(color, iob, prefix, " ", bold=true) + printstyled(iob, prefix, " ", bold=true, color=color) end print(iob, " "^indent, msg) if i == length(msglines) && !isempty(suffix) npad = max(0, justify_width - nonpadwidth) + minsuffixpad print(iob, " "^npad) - print_with_color(:light_black, iob, suffix) + printstyled(iob, suffix, color=:light_black) end println(iob) end diff --git a/stdlib/REPL/src/precompile.jl b/stdlib/REPL/src/precompile.jl index 87042ba8aff2d..279ce2a17b7cd 100644 --- a/stdlib/REPL/src/precompile.jl +++ b/stdlib/REPL/src/precompile.jl @@ -145,8 +145,7 @@ function _precompile_() precompile(Tuple{typeof(Base.print), Base.IOContext{REPL.Terminals.TTYTerminal}, String, Module}) precompile(Tuple{typeof(Base.print), Base.IOContext{REPL.Terminals.TTYTerminal}, String, Symbol, String, Int32}) precompile(Tuple{typeof(Base.show_tuple_as_call), Base.IOContext{REPL.Terminals.TTYTerminal}, Symbol, Type}) - precompile(Tuple{typeof(Base.print_with_color), Symbol, Base.IOContext{REPL.Terminals.TTYTerminal}, String}) - precompile(Tuple{typeof(Base.print_with_color), Int64, Base.IOContext{REPL.Terminals.TTYTerminal}, String}) + precompile(Tuple{typeof(getfield(Base, Symbol("#kw##printstyled"))), Array{Any,1}, typeof(Base.printstyled), Base.IOContext{REPL.Terminals.TTYTerminal}, String}) precompile(Tuple{typeof(Base.show), Base.IOContext{REPL.Terminals.TTYTerminal}, Core.MethodInstance}) precompile(Tuple{typeof(Base.StackTraces.show_spec_linfo), Base.IOContext{REPL.Terminals.TTYTerminal}, Base.StackTraces.StackFrame}) precompile(Tuple{getfield(Base, Symbol("#kw##show")), Array{Any, 1}, typeof(Base.show), Base.IOContext{REPL.Terminals.TTYTerminal}, Base.StackTraces.StackFrame}) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 847a9296a9e7d..517be6e9ec73d 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -70,7 +70,7 @@ struct Pass <: Result value end function Base.show(io::IO, t::Pass) - print_with_color(:green, io, "Test Passed"; bold = true) + printstyled(io, "Test Passed"; bold = true, color=:green) if !(t.orig_expr === nothing) print(io, "\n Expression: ", t.orig_expr) end @@ -98,9 +98,9 @@ mutable struct Fail <: Result source::LineNumberNode end function Base.show(io::IO, t::Fail) - print_with_color(Base.error_color(), io, "Test Failed"; bold = true) + printstyled(io, "Test Failed"; bold=true, color=Base.error_color()) print(io, " at ") - print_with_color(:default, io, t.source.file, ":", t.source.line, "\n"; bold = true) + printstyled(io, t.source.file, ":", t.source.line, "\n"; bold=true, color=:default) print(io, " Expression: ", t.orig_expr) if t.test_type == :test_throws_wrong # An exception was thrown, but it was of the wrong type @@ -134,12 +134,12 @@ mutable struct Error <: Result end function Base.show(io::IO, t::Error) if t.test_type == :test_interrupted - print_with_color(Base.error_color(), io, "Interrupted") + printstyled(io, "Interrupted", color=Base.error_color()) return end - print_with_color(Base.error_color(), io, "Error During Test"; bold = true) + printstyled(io, "Error During Test"; bold=true, color=Base.error_color()) print(io, " at ") - print_with_color(:default, io, t.source.file, ":", t.source.line, "\n"; bold = true) + printstyled(io, t.source.file, ":", t.source.line, "\n"; bold=true, color=:default) if t.test_type == :test_nonbool println(io, " Expression evaluated to non-Boolean") println(io, " Expression: ", t.orig_expr) @@ -177,7 +177,7 @@ mutable struct Broken <: Result orig_expr end function Base.show(io::IO, t::Broken) - print_with_color(Base.warn_color(), io, "Test Broken\n"; bold = true) + printstyled(io, "Test Broken\n"; bold=true, color=Base.warn_color()) if t.test_type == :skipped && !(t.orig_expr === nothing) println(io, " Skipped: ", t.orig_expr) elseif !(t.orig_expr === nothing) @@ -615,7 +615,7 @@ function Base.show(io::IO, ex::TestSetException) end function Base.showerror(io::IO, ex::TestSetException, bt; backtrace=true) - print_with_color(Base.error_color(), io, string(ex)) + printstyled(io, string(ex), color=Base.error_color()) end #----------------------------------------------------------------------- @@ -633,7 +633,7 @@ struct FallbackTestSetException <: Exception end function Base.showerror(io::IO, ex::FallbackTestSetException, bt; backtrace=true) - print_with_color(Base.error_color(), io, ex.msg) + printstyled(io, ex.msg, color=Base.error_color()) end # Records nothing, and throws an error immediately whenever a Fail or @@ -672,7 +672,7 @@ record(ts::DefaultTestSet, t::Pass) = (ts.n_passed += 1; t) # but do not terminate. Print a backtrace. function record(ts::DefaultTestSet, t::Union{Fail, Error}) if myid() == 1 - print_with_color(:white, ts.description, ": ") + printstyled(ts.description, ": ", color=:white) # don't print for interrupted tests if !(t isa Error) || t.test_type != :test_interrupted print(t) @@ -731,21 +731,21 @@ function print_test_results(ts::DefaultTestSet, depth_pad=0) align = max(get_alignment(ts, 0), length("Test Summary:")) # Print the outer test set header once pad = total == 0 ? "" : " " - print_with_color(:white, rpad("Test Summary:",align," "), " |", pad; bold = true) + printstyled(rpad("Test Summary:", align, " "), " |", pad; bold=true, color=:white) if pass_width > 0 - print_with_color(:green, lpad("Pass",pass_width," "), " "; bold = true) + printstyled(lpad("Pass", pass_width, " "), " "; bold=true, color=:green) end if fail_width > 0 - print_with_color(Base.error_color(), lpad("Fail",fail_width," "), " "; bold = true) + printstyled(lpad("Fail", fail_width, " "), " "; bold=true, color=Base.error_color()) end if error_width > 0 - print_with_color(Base.error_color(), lpad("Error",error_width," "), " "; bold = true) + printstyled(lpad("Error", error_width, " "), " "; bold=true, color=Base.error_color()) end if broken_width > 0 - print_with_color(Base.warn_color(), lpad("Broken",broken_width," "), " "; bold = true) + printstyled(lpad("Broken", broken_width, " "), " "; bold=true, color=Base.warn_color()) end if total_width > 0 - print_with_color(Base.info_color(), lpad("Total",total_width, " "); bold = true) + printstyled(lpad("Total", total_width, " "); bold=true, color=Base.info_color()) end println() # Recursively print a summary at every level @@ -855,7 +855,7 @@ function print_counts(ts::DefaultTestSet, depth, align, np = passes + c_passes if np > 0 - print_with_color(:green, lpad(string(np), pass_width, " "), " ") + printstyled(lpad(string(np), pass_width, " "), " ", color=:green) elseif pass_width > 0 # No passes at this level, but some at another level print(lpad(" ", pass_width), " ") @@ -863,7 +863,7 @@ function print_counts(ts::DefaultTestSet, depth, align, nf = fails + c_fails if nf > 0 - print_with_color(Base.error_color(), lpad(string(nf), fail_width, " "), " ") + printstyled(lpad(string(nf), fail_width, " "), " ", color=Base.error_color()) elseif fail_width > 0 # No fails at this level, but some at another level print(lpad(" ", fail_width), " ") @@ -871,7 +871,7 @@ function print_counts(ts::DefaultTestSet, depth, align, ne = errors + c_errors if ne > 0 - print_with_color(Base.error_color(), lpad(string(ne), error_width, " "), " ") + printstyled(lpad(string(ne), error_width, " "), " ", color=Base.error_color()) elseif error_width > 0 # No errors at this level, but some at another level print(lpad(" ", error_width), " ") @@ -879,16 +879,16 @@ function print_counts(ts::DefaultTestSet, depth, align, nb = broken + c_broken if nb > 0 - print_with_color(Base.warn_color(), lpad(string(nb), broken_width, " "), " ") + printstyled(lpad(string(nb), broken_width, " "), " ", color=Base.warn_color()) elseif broken_width > 0 # None broken at this level, but some at another level print(lpad(" ", broken_width), " ") end if np == 0 && nf == 0 && ne == 0 && nb == 0 - print_with_color(Base.info_color(), "No tests") + printstyled("No tests", color=Base.info_color()) else - print_with_color(Base.info_color(), lpad(string(subtotal), total_width, " ")) + printstyled(lpad(string(subtotal), total_width, " "), color=Base.info_color()) end println() diff --git a/stdlib/Test/src/logging.jl b/stdlib/Test/src/logging.jl index e31b07c448d75..9dc8782a6a57c 100644 --- a/stdlib/Test/src/logging.jl +++ b/stdlib/Test/src/logging.jl @@ -64,9 +64,9 @@ mutable struct LogTestFailure <: Result logs end function Base.show(io::IO, t::LogTestFailure) - print_with_color(Base.error_color(), io, "Log Test Failed"; bold = true) + printstyled(io, "Log Test Failed"; bold=true, color=Base.error_color()) print(io, " at ") - print_with_color(:default, io, t.source.file, ":", t.source.line, "\n"; bold = true) + printstyled(io, t.source.file, ":", t.source.line, "\n"; bold=true, color=:default) println(io, " Expression: ", t.orig_expr) println(io, " Log Pattern: ", join(t.patterns, " ")) println(io, " Captured Logs: ") @@ -84,7 +84,7 @@ end function record(ts::DefaultTestSet, t::LogTestFailure) if myid() == 1 - print_with_color(:white, ts.description, ": ") + printstyled(ts.description, ": ", color=:white) print(t) Base.show_backtrace(STDOUT, scrub_backtrace(backtrace())) println() diff --git a/test/misc.jl b/test/misc.jl index 4d65bc6f18054..69906755c680b 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -465,14 +465,14 @@ if Sys.iswindows() end let buf = IOBuffer() - print_with_color(:red, IOContext(buf, :color=>true), "foo") + printstyled(IOContext(buf, :color=>true), "foo", color=:red) @test startswith(String(take!(buf)), Base.text_colors[:red]) end -# Test that `print_with_color` accepts non-string values, just as `print` does +# Test that `printstyled` accepts non-string values, just as `print` does let buf_color = IOBuffer() args = (3.2, "foo", :testsym) - print_with_color(:red, IOContext(buf_color, :color=>true), args...) + printstyled(IOContext(buf_color, :color=>true), args..., color=:red) buf_plain = IOBuffer() print(buf_plain, args...) expected_str = string(Base.text_colors[:red], @@ -481,11 +481,11 @@ let buf_color = IOBuffer() @test expected_str == String(take!(buf_color)) end -# Test that `print_with_color` on multiline input prints the ANSI codes +# Test that `printstyled` on multiline input prints the ANSI codes # on each line let buf_color = IOBuffer() str = "Two\nlines" - print_with_color(:red, IOContext(buf_color, :color=>true), str; bold=true) + printstyled(IOContext(buf_color, :color=>true), str; bold=true, color=:red) @test String(take!(buf_color)) == "\e[31m\e[1mTwo\e[22m\e[39m\n\e[31m\e[1mlines\e[22m\e[39m" end @@ -511,12 +511,12 @@ end let buf = IOBuffer() buf_color = IOContext(buf, :color => true) - print_with_color(:red, buf_color, "foo") + printstyled(buf_color, "foo", color=:red) # Check that we get back to normal text color in the end @test String(take!(buf)) == "\e[31mfoo\e[39m" # Check that boldness is turned off - print_with_color(:red, buf_color, "foo"; bold = true) + printstyled(buf_color, "foo"; bold=true, color=:red) @test String(take!(buf)) == "\e[31m\e[1mfoo\e[22m\e[39m" end diff --git a/test/runtests.jl b/test/runtests.jl index e7b249dff2f7d..510362d503b41 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -67,28 +67,28 @@ cd(dirname(@__FILE__)) do percent_align = length("GC %") alloc_align = length("Alloc (MB)") rss_align = length("RSS (MB)") - print_with_color(:white, rpad("Test (Worker)",name_align," "), " | ") - print_with_color(:white, "Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB)\n") + printstyled(rpad("Test (Worker)", name_align, " "), " | ", color=:white) + printstyled("Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB)\n", color=:white) results=[] print_lock = ReentrantLock() function print_testworker_stats(test, wrkr, resp) lock(print_lock) try - print_with_color(:white, rpad(test*" ($wrkr)", name_align, " "), " | ") + printstyled(rpad(test*" ($wrkr)", name_align, " "), " | ", color=:white) time_str = @sprintf("%7.2f",resp[2]) - print_with_color(:white, rpad(time_str,elapsed_align," "), " | ") + printstyled(rpad(time_str,elapsed_align," "), " | ", color=:white) gc_str = @sprintf("%5.2f",resp[5].total_time/10^9) - print_with_color(:white, rpad(gc_str,gc_align," "), " | ") + printstyled(rpad(gc_str, gc_align, " "), " | ", color=:white) # since there may be quite a few digits in the percentage, # the left-padding here is less to make sure everything fits percent_str = @sprintf("%4.1f",100*resp[5].total_time/(10^9*resp[2])) - print_with_color(:white, rpad(percent_str,percent_align," "), " | ") + printstyled(rpad(percent_str, percent_align, " "), " | ", color=:white) alloc_str = @sprintf("%5.2f",resp[3]/2^20) - print_with_color(:white, rpad(alloc_str,alloc_align," "), " | ") + printstyled(rpad(alloc_str, alloc_align, " "), " | ", color=:white) rss_str = @sprintf("%5.2f",resp[6]/2^20) - print_with_color(:white, rpad(rss_str,rss_align," "), "\n") + printstyled(rpad(rss_str, rss_align, " "), "\n", color=:white) finally unlock(print_lock) end