Skip to content

Commit dbc0eae

Browse files
authored
Merge pull request #2 from JuliaPackaging/mg/have-color
Get value of `Base.have_color` with `something`
2 parents ba7fac5 + 0fa7b76 commit dbc0eae

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OutputCollectors"
22
uuid = "6c11c7d4-943b-4e2b-80de-f2cfc2930a8c"
33
authors = ["Elliot Saba <[email protected]>"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[compat]
77
julia = "1"

src/OutputCollectors.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import Base: wait, merge
77

88
export OutputCollector, merge, collect_stdout, collect_stderr, tail, tee
99

10+
# Make sure we don't have problems when `Base.have_color` is `nothing`.
11+
function get_have_color()
12+
@static if isdefined(Base, :get_have_color)
13+
return Base.get_have_color()
14+
else
15+
# Compatibility with Julia v1.4-. Layman check for coloured output on
16+
# older Julia versions. TODO: remove this function when we drop support
17+
# for oldere versions of Julia.
18+
return something(Base.have_color, false)
19+
end
20+
end
21+
1022
struct LineStream
1123
pipe::Pipe
1224
lines::Vector{Tuple{Float64,String}}
@@ -168,7 +180,7 @@ function wait(collector::OutputCollector)
168180
# If we failed, print out the tail of the output, unless we've been
169181
# tee()'ing it out this whole time, but only if the user said it's okay.
170182
if !success(collector.P) && !collector.verbose && collector.tail_error
171-
our_tail = tail(collector; colored=Base.have_color)
183+
our_tail = tail(collector; colored=get_have_color())
172184
print(collector.tee_stream, our_tail)
173185
end
174186
end
@@ -290,7 +302,7 @@ end
290302
Spawn a background task to incrementally output lines from `collector` to the
291303
standard output, optionally colored.
292304
"""
293-
function tee(c::OutputCollector; colored::Bool=Base.have_color,
305+
function tee(c::OutputCollector; colored::Bool=get_have_color(),
294306
stream::IO=stdout)
295307
tee_task = @async begin
296308
out_idx = 1

0 commit comments

Comments
 (0)