@Sukera for reference, I think this mostly does what I want without having to go through intercepting calls to print directly. The code is based on the awesome Suppressors.jl package.
original_stdout = stdout
out_rd, out_wr = redirect_stdout()
out_reader = @async read(out_rd, String)
for i in 1:5
println("show later")
println(original_stdout, "shownow")
end
redirect_stdout(original_stdout)
close(out_wr)
out = fetch(out_reader)
print(out)
print("done")
With output
shownow
shownow
shownow
shownow
shownow
show later
show later
show later
show later
show later
done
The idea is that any call like print("text") will not show until I’ve restored the original STDOUT stream, but I can use println(original_stdout, "text") display things immediately. So the way it’s going to play out is that when the progress bar is created I re-direct the stdout:
original_stdout = stdout
out_rd, out_wr = redirect_stdout()
out_reader = @async read(out_rd, String)
Then during the loop the user can use print as they do normally, but the output won’t show immediately.
When the loop is done and the progress bar stopped, it can restore the normal stdout behavior and print out anything that was captured by the re-directed stream.