Skip to content

Commit 4cc0970

Browse files
committed
Add printstyled
1 parent fbc1559 commit 4cc0970

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ Currently, the `@compat` macro supports the following syntaxes:
253253
* `codeunits(s)` returns an array-like view of the `UInt8` code units of
254254
a string and `ncodeunits(s)` returns the number of code units ([#25241]).
255255

256+
* `printstyled` prints to a given stream optionally in color and/or bolded ([#25522]).
257+
256258
* `Dates.Period` rounding (e.g., `round(Dates.Hour(36), Dates.Day, RoundNearestTiesUp) == Dates.Day(2)` ([#24182]).
257259

258260

@@ -510,6 +512,7 @@ includes this fix. Find the minimum version from there.
510512
[#25458]: https://github.com/JuliaLang/julia/issues/25458
511513
[#25459]: https://github.com/JuliaLang/julia/issues/25459
512514
[#25496]: https://github.com/JuliaLang/julia/issues/25496
515+
[#25522]: https://github.com/JuliaLang/julia/issues/25522
513516
[#25544]: https://github.com/JuliaLang/julia/issues/25544
514517
[#25545]: https://github.com/JuliaLang/julia/issues/25545
515518
[#25571]: https://github.com/JuliaLang/julia/issues/25571

src/Compat.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,15 @@ end
14971497
export lastindex
14981498
end
14991499

1500+
# 0.7.0-DEV.3585
1501+
@static if !isdefined(Base, :printstyled)
1502+
printstyled(io::IO, msg...; bold=false, color=:normal) =
1503+
Base.print_with_color(color, io, msg...; bold=bold)
1504+
printstyled(msg...; bold=false, color=:normal) =
1505+
Base.print_with_color(color, STDOUT, msg...; bold=bold)
1506+
export printstyled
1507+
end
1508+
15001509
include("deprecated.jl")
15011510

15021511
end # module Compat

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,4 +1297,10 @@ end
12971297
@test lastindex(zeros(4)) == 4
12981298
@test lastindex(zeros(4,4)) == 16
12991299

1300+
# 0.7.0-DEV.3585
1301+
let buf = IOBuffer()
1302+
printstyled(IOContext(buf, :color=>true), "foo", color=:red)
1303+
@test startswith(String(take!(buf)), Base.text_colors[:red])
1304+
end
1305+
13001306
nothing

0 commit comments

Comments
 (0)