Skip to content

Commit

Permalink
Add printstyled (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored Feb 3, 2018
1 parent 19bad8c commit f2bd1a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).


Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1305,4 +1305,17 @@ end
@test lastindex(zeros(4)) == 4
@test lastindex(zeros(4,4)) == 16

# 0.7.0-DEV.3585
let buf = IOBuffer()
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

nothing

0 comments on commit f2bd1a9

Please sign in to comment.