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

fix multi-line string in showvalues #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion src/ProgressMeter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@ function finish!(p::ProgressUnknown; options...)
end
end

function replace_EOL_with_space(s)
width = displaysize(stdout)[2]
lines = split(s, "\n")
filled = lines .* " ".^(width .- sizeof.(lines))
return join(filled)
end

# Internal method to print additional values below progress bar
function printvalues!(p::AbstractProgress, showvalues; color = :normal, truncate = false)
length(showvalues) == 0 && return
Expand All @@ -591,7 +598,7 @@ function printvalues!(p::AbstractProgress, showvalues; color = :normal, truncate
p.numprintedvalues = 0

for (name, value) in showvalues
msg = "\n " * rpad(string(name) * ": ", maxwidth+2+1) * string(value)
msg = "\n " * rpad(string(name) * ": ", maxwidth+2+1) * replace_EOL_with_space(string(value))
max_len = (displaysize(p.output)::Tuple{Int,Int})[2]
# I don't understand why the minus 1 is necessary here, but empircally
# it is needed.
Expand Down
8 changes: 8 additions & 0 deletions test/test_showvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ for i in 1:50
sleep(0.1)
end

println("Testing multi-line string")
p = ProgressMeter.Progress(10)
for iter in 1:10
sleep(0.1)
s = "line 1\nline 2\nline 3"
next!(p; showvalues = [("lines", s)])
end

end # if