79747092

Date: 2025-08-26 16:42:12
Score: 0.5
Natty:
Report link

The answer above wasn't working for me when called from within a function for some reason...but I found that adding the clear command to a run block before printing works to clear the console. I was trying to write some text and make a plot with UnicodePlots, so here is a MWE for anyone else looking to do something similar:

using UnicodePlots

function progressPlot!(i, n, x, y)  
    run(`printf "\033c"`) #clear the screen, from https://stackoverflow.com/questions/5367068/clear-a-terminal-screen-for-real/5367075#5367075
    print("some message about status of iteration $i/$n\n")
    p=lineplot(x, y)
    Base.show(stdout, p)
    flush(stdout)
end

function main()
    x = 0:100
    y = sin.(x)
    for i=1:100
        progressPlot!(i, 100, x[1:i], y[1:i])
        sleep(0.01)
    end
end

main()
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: kirklong