Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back color printing #647

Merged
merged 2 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/DocChecks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function missingdocs(doc::Documents.Document)
end
end
push!(doc.internal.errors, :missing_docs)
Utilities.warn(Utilities.takebuf_str(b))
Utilities.warn(String(take!(b)))
end
end

Expand Down Expand Up @@ -303,31 +303,32 @@ function sanitise(buffer)
for line in eachline(seekstart(buffer))
println(out, rstrip(line))
end
remove_term_colors(rstrip(Utilities.takebuf_str(out), '\n'))
remove_term_colors(rstrip(String(take!(out)), '\n'))
end

import .Utilities.TextDiff

function report(result::Result, str, doc::Documents.Document)
buffer = IOBuffer()
println(buffer, "=====[Test Error]", "="^30)
println(buffer)
printstyled(buffer, "> File: ", result.file, "\n", color=:cyan)
printstyled(buffer, "\n> Code block:\n", color=:cyan)
println(buffer, "\n```jldoctest")
println(buffer, result.code)
println(buffer, "```")
iob = IOBuffer()
ioc = IOContext(iob, :color => Base.have_color)
println(ioc, "=====[Test Error]", "="^30)
println(ioc)
printstyled(ioc, "> File: ", result.file, "\n", color=:cyan)
printstyled(ioc, "\n> Code block:\n", color=:cyan)
println(ioc, "\n```jldoctest")
println(ioc, result.code)
println(ioc, "```")
if !isempty(result.input)
printstyled(buffer, "\n> Subexpression:\n", color=:cyan)
print_indented(buffer, result.input; indent = 4)
printstyled(ioc, "\n> Subexpression:\n", color=:cyan)
print_indented(ioc, result.input; indent = 4)
end
warning = Base.have_color ? "" : " (REQUIRES COLOR)"
printstyled(buffer, "\n> Output Diff", warning, ":\n\n", color=:cyan)
printstyled(ioc, "\n> Output Diff", warning, ":\n\n", color=:cyan)
diff = TextDiff.Diff{TextDiff.Words}(result.output, rstrip(str))
Utilities.TextDiff.showdiff(buffer, diff)
println(buffer, "\n\n", "=====[End Error]=", "="^30)
Utilities.TextDiff.showdiff(ioc, diff)
println(ioc, "\n\n", "=====[End Error]=", "="^30)
push!(doc.internal.errors, :doctest)
printstyled(Utilities.takebuf_str(buffer), color=:normal)
printstyled(String(take!(iob)), color=:normal)
end

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

function savebuffer!(out, buf)
n = bytesavailable(seekstart(buf))
n > 0 ? push!(out, rstrip(Utilities.takebuf_str(buf))) : out
n > 0 ? push!(out, rstrip(String(take!(buf)))) : out
end

function takeuntil!(r, buf, lines)
Expand Down
6 changes: 3 additions & 3 deletions src/Expanders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ function Selectors.runner(::Type{REPLBlocks}, x, page, doc)
println(out, output, "\n")
end
end
page.mapping[x] = Markdown.Code("julia-repl", rstrip(Utilities.takebuf_str(out)))
page.mapping[x] = Markdown.Code("julia-repl", rstrip(String(take!(out))))
end

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

function prepend_prompt(input)
Expand All @@ -594,7 +594,7 @@ function prepend_prompt(input)
line = rstrip(line)
println(out, n == 1 ? prompt : padding, line)
end
rstrip(Utilities.takebuf_str(out))
rstrip(String(take!(out)))
end

end
6 changes: 3 additions & 3 deletions src/Utilities/DOM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ function attributes!(out, s::AbstractString)
for x in eachmatch(r"[#|\.]([\w\-]+)", s)
print(startswith(x.match, '.') ? class : id, x.captures[1], ' ')
end
position(class) === 0 || push!(out, tostr(:class => rstrip(Utilities.takebuf_str(class))))
position(id) === 0 || push!(out, tostr(:id => rstrip(Utilities.takebuf_str(id))))
position(class) === 0 || push!(out, tostr(:class => rstrip(String(take!(class)))))
position(id) === 0 || push!(out, tostr(:id => rstrip(String(take!(id)))))
return out
end
attributes!(out, s::Symbol) = push!(out, tostr(s => ""))
Expand Down Expand Up @@ -293,7 +293,7 @@ function escapehtml(text::AbstractString)
char === '\'' ? write(buffer, "'") :
char === '"' ? write(buffer, """) : write(buffer, char)
end
Utilities.takebuf_str(buffer)
String(take!(buffer))
else
text
end
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/MDFlatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ then be used as input for search engines.
function mdflatten(md)
io = IOBuffer()
mdflatten(io, md)
Utilities.takebuf_str(io)
String(take!(io))
end

mdflatten(io, md) = mdflatten(io, md, md)
Expand Down
4 changes: 1 addition & 3 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function check_kwargs(kws)
for (k, v) in kws
println(out, " ", k, " = ", v)
end
warn(Utilities.takebuf_str(out))
warn(String(take!(out)))
end

# Finding submodules.
Expand Down Expand Up @@ -336,8 +336,6 @@ nodocs(::Nothing) = false

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

takebuf_str(b) = String(take!(b))

# Finding URLs -- based partially on code from the main Julia repo in `base/methodshow.jl`.
#
# Paths on Windows contain backslashes, so the `url` function needs to take care of them.
Expand Down
4 changes: 2 additions & 2 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function render(doc::Documents.Document)

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