Skip to content

Commit dcc0c14

Browse files
authored
Merge pull request #647 from JuliaDocs/fe/color
Bring back color printing
2 parents b957845 + 974fb7c commit dcc0c14

File tree

6 files changed

+28
-29
lines changed

6 files changed

+28
-29
lines changed

src/DocChecks.jl

+18-17
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function missingdocs(doc::Documents.Document)
5151
end
5252
end
5353
push!(doc.internal.errors, :missing_docs)
54-
Utilities.warn(Utilities.takebuf_str(b))
54+
Utilities.warn(String(take!(b)))
5555
end
5656
end
5757

@@ -303,31 +303,32 @@ function sanitise(buffer)
303303
for line in eachline(seekstart(buffer))
304304
println(out, rstrip(line))
305305
end
306-
remove_term_colors(rstrip(Utilities.takebuf_str(out), '\n'))
306+
remove_term_colors(rstrip(String(take!(out)), '\n'))
307307
end
308308

309309
import .Utilities.TextDiff
310310

311311
function report(result::Result, str, doc::Documents.Document)
312-
buffer = IOBuffer()
313-
println(buffer, "=====[Test Error]", "="^30)
314-
println(buffer)
315-
printstyled(buffer, "> File: ", result.file, "\n", color=:cyan)
316-
printstyled(buffer, "\n> Code block:\n", color=:cyan)
317-
println(buffer, "\n```jldoctest")
318-
println(buffer, result.code)
319-
println(buffer, "```")
312+
iob = IOBuffer()
313+
ioc = IOContext(iob, :color => Base.have_color)
314+
println(ioc, "=====[Test Error]", "="^30)
315+
println(ioc)
316+
printstyled(ioc, "> File: ", result.file, "\n", color=:cyan)
317+
printstyled(ioc, "\n> Code block:\n", color=:cyan)
318+
println(ioc, "\n```jldoctest")
319+
println(ioc, result.code)
320+
println(ioc, "```")
320321
if !isempty(result.input)
321-
printstyled(buffer, "\n> Subexpression:\n", color=:cyan)
322-
print_indented(buffer, result.input; indent = 4)
322+
printstyled(ioc, "\n> Subexpression:\n", color=:cyan)
323+
print_indented(ioc, result.input; indent = 4)
323324
end
324325
warning = Base.have_color ? "" : " (REQUIRES COLOR)"
325-
printstyled(buffer, "\n> Output Diff", warning, ":\n\n", color=:cyan)
326+
printstyled(ioc, "\n> Output Diff", warning, ":\n\n", color=:cyan)
326327
diff = TextDiff.Diff{TextDiff.Words}(result.output, rstrip(str))
327-
Utilities.TextDiff.showdiff(buffer, diff)
328-
println(buffer, "\n\n", "=====[End Error]=", "="^30)
328+
Utilities.TextDiff.showdiff(ioc, diff)
329+
println(ioc, "\n\n", "=====[End Error]=", "="^30)
329330
push!(doc.internal.errors, :doctest)
330-
printstyled(Utilities.takebuf_str(buffer), color=:normal)
331+
printstyled(String(take!(iob)), color=:normal)
331332
end
332333

333334
function print_indented(buffer::IO, str::AbstractString; indent = 4)
@@ -381,7 +382,7 @@ end
381382

382383
function savebuffer!(out, buf)
383384
n = bytesavailable(seekstart(buf))
384-
n > 0 ? push!(out, rstrip(Utilities.takebuf_str(buf))) : out
385+
n > 0 ? push!(out, rstrip(String(take!(buf)))) : out
385386
end
386387

387388
function takeuntil!(r, buf, lines)

src/Expanders.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ function Selectors.runner(::Type{REPLBlocks}, x, page, doc)
519519
println(out, output, "\n")
520520
end
521521
end
522-
page.mapping[x] = Markdown.Code("julia-repl", rstrip(Utilities.takebuf_str(out)))
522+
page.mapping[x] = Markdown.Code("julia-repl", rstrip(String(take!(out))))
523523
end
524524

525525
# @setup
@@ -583,7 +583,7 @@ function droplines(code; skip = 0)
583583
contains(line, r"^(.*)# hide$") && continue
584584
println(buffer, rstrip(line))
585585
end
586-
strip(Utilities.takebuf_str(buffer), '\n')
586+
strip(String(take!(buffer)), '\n')
587587
end
588588

589589
function prepend_prompt(input)
@@ -594,7 +594,7 @@ function prepend_prompt(input)
594594
line = rstrip(line)
595595
println(out, n == 1 ? prompt : padding, line)
596596
end
597-
rstrip(Utilities.takebuf_str(out))
597+
rstrip(String(take!(out)))
598598
end
599599

600600
end

src/Utilities/DOM.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ function attributes!(out, s::AbstractString)
234234
for x in eachmatch(r"[#|\.]([\w\-]+)", s)
235235
print(startswith(x.match, '.') ? class : id, x.captures[1], ' ')
236236
end
237-
position(class) === 0 || push!(out, tostr(:class => rstrip(Utilities.takebuf_str(class))))
238-
position(id) === 0 || push!(out, tostr(:id => rstrip(Utilities.takebuf_str(id))))
237+
position(class) === 0 || push!(out, tostr(:class => rstrip(String(take!(class)))))
238+
position(id) === 0 || push!(out, tostr(:id => rstrip(String(take!(id)))))
239239
return out
240240
end
241241
attributes!(out, s::Symbol) = push!(out, tostr(s => ""))
@@ -293,7 +293,7 @@ function escapehtml(text::AbstractString)
293293
char === '\'' ? write(buffer, "'") :
294294
char === '"' ? write(buffer, """) : write(buffer, char)
295295
end
296-
Utilities.takebuf_str(buffer)
296+
String(take!(buffer))
297297
else
298298
text
299299
end

src/Utilities/MDFlatten.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ then be used as input for search engines.
2828
function mdflatten(md)
2929
io = IOBuffer()
3030
mdflatten(io, md)
31-
Utilities.takebuf_str(io)
31+
String(take!(io))
3232
end
3333

3434
mdflatten(io, md) = mdflatten(io, md, md)

src/Utilities/Utilities.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function check_kwargs(kws)
157157
for (k, v) in kws
158158
println(out, " ", k, " = ", v)
159159
end
160-
warn(Utilities.takebuf_str(out))
160+
warn(String(take!(out)))
161161
end
162162

163163
# Finding submodules.
@@ -336,8 +336,6 @@ nodocs(::Nothing) = false
336336

337337
header_level(::Markdown.Header{N}) where {N} = N
338338

339-
takebuf_str(b) = String(take!(b))
340-
341339
# Finding URLs -- based partially on code from the main Julia repo in `base/methodshow.jl`.
342340
#
343341
# Paths on Windows contain backslashes, so the `url` function needs to take care of them.

src/Writers/HTMLWriter.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function render(doc::Documents.Document)
138138

139139
open(joinpath(doc.user.build, ctx.search_index_js), "w") do io
140140
println(io, "var documenterSearchIndex = {\"docs\": [\n")
141-
write(io, Utilities.takebuf_str(ctx.search_index))
141+
write(io, String(take!(ctx.search_index)))
142142
println(io, "]}")
143143
end
144144
end
@@ -550,7 +550,7 @@ function search_flush(sib)
550550
# Replace any backslashes in links, if building the docs on Windows
551551
src = replace(sib.src, '\\' => '/')
552552
ref = "$(src)#$(sib.loc)"
553-
text = Utilities.takebuf_str(sib.buffer)
553+
text = String(take!(sib.buffer))
554554
println(sib.ctx.search_index, """
555555
{
556556
"location": "$(jsescape(ref))",

0 commit comments

Comments
 (0)