From 5be9dd8a81bec39947df5aed280c198a561fd569 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Thu, 1 Feb 2018 14:42:02 -0800 Subject: [PATCH 1/2] Add printstyled --- README.md | 3 +++ src/Compat.jl | 9 +++++++++ test/runtests.jl | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 1f7795178..de8f4b681 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `codeunits(s)` returns an array-like view of the `UInt8` code units of a string and `ncodeunits(s)` returns the number of code units ([#25241]). +* `printstyled` prints to a given stream optionally in color and/or bolded ([#25522]). + * `Dates.Period` rounding (e.g., `round(Dates.Hour(36), Dates.Day, RoundNearestTiesUp) == Dates.Day(2)` ([#24182]). @@ -513,6 +515,7 @@ includes this fix. Find the minimum version from there. [#25458]: https://github.com/JuliaLang/julia/issues/25458 [#25459]: https://github.com/JuliaLang/julia/issues/25459 [#25496]: https://github.com/JuliaLang/julia/issues/25496 +[#25522]: https://github.com/JuliaLang/julia/issues/25522 [#25544]: https://github.com/JuliaLang/julia/issues/25544 [#25545]: https://github.com/JuliaLang/julia/issues/25545 [#25571]: https://github.com/JuliaLang/julia/issues/25571 diff --git a/src/Compat.jl b/src/Compat.jl index ea464cecd..6bf19888b 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1509,6 +1509,15 @@ end export lastindex end +# 0.7.0-DEV.3585 +@static if !isdefined(Base, :printstyled) + printstyled(io::IO, msg...; bold=false, color=:normal) = + Base.print_with_color(color, io, msg...; bold=bold) + printstyled(msg...; bold=false, color=:normal) = + Base.print_with_color(color, STDOUT, msg...; bold=bold) + export printstyled +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index a3a28a206..ed1bc6d3e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1305,4 +1305,10 @@ end @test lastindex(zeros(4)) == 4 @test lastindex(zeros(4,4)) == 16 +# 0.7.0-DEV.3585 +let buf = IOBuffer() + printstyled(IOContext(buf, :color=>true), "foo", color=:red) + @test startswith(String(take!(buf)), Base.text_colors[:red]) +end + nothing From 4e5d84fda4466d0d01430fd5080099c4b4faeef6 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 2 Feb 2018 23:10:49 -0800 Subject: [PATCH 2/2] Try to fix test on 0.6 --- test/runtests.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index ed1bc6d3e..b3287a06a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1307,7 +1307,14 @@ end # 0.7.0-DEV.3585 let buf = IOBuffer() - printstyled(IOContext(buf, :color=>true), "foo", color=:red) + if VERSION < v"0.7.0-DEV.3077" + col = Base.have_color + eval(Base, :(have_color = true)) + printstyled(buf, "foo", color=:red) + eval(Base, :(have_color = $col)) + else + printstyled(IOContext(buf, :color=>true), "foo", color=:red) + end @test startswith(String(take!(buf)), Base.text_colors[:red]) end